Mostly Linux & Python syntax notes and hyperlinks.

Friday, January 8, 2010

python: looping through filenames in a directory

import os
...
dirname=os.getcwd()
ext_name=".txt"
...
try:
        for file in os.listdir(dirname):
            if file.endswith(ext_name):
                #do whatever
except:

No comments:

Post a Comment