Is it possible in python to open all files in a directory?

this only opens a particular file:

import os

path = "/Desktop/directory/file.odt"

temp = os.system("open " + path)

how about this? am i doing it right?

import os

mypath = "/Desktop/directory"

temp = os.listdir(mypath) 

temp = [os.path.join(mypath, i) 
for i in temp:
    if os.path.splitext(f)[1] in mytemp]

os.system("open " + temp)

Advises and comments are very much appreciated. Thank you

I'd imagine it'd be something like

import os
import glob # If you are running *nix. Looks like you are

mypath = '/Desktop/directory/'
files_in_directory = glob.glob(mypath) # Creates a list of all the files in your directory
'''This a comment. If you only wanted, say text files to show up in 
the list above, use this. 
files_in_directory = glob.glob('%s*.txt'%mypath)'''
for file in files_in_directory: # Go through the files
    os.system('open'+file) # Open them

But I am not near my computer that has Python on it so hope this helps a bit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.