0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by redyugi
0

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

Edited by redyugi: Needed a couple comments

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.