DoingSomethingWithAllFilesInaDirectory
Revision as of 13:54, 11 September 2009 by Michael Murtaugh (talk | contribs) (→DoingSomethingWithAllFilesInaDirectory)
You want to do something repeatedly to all the files (or maybe all files with a certain extension) in a directory, no matter how "deep" inside folders those files may be.
From the commandline, you can use the wonderful(ly cryptic and difficult) find command, together with the "exec" option:
find . -name "*.py" -exec echo {} \;
In Python, you can use the os.walk function:
#!python numbers=off import os.path for (dirpath, dirnames, filenames) in os.walk("."): for f in filenames: #if f.endswith(".py"): print os.path.join(dirpath,f)