Recurse Directories and process files in directory
Gary Herron
gherron at islandtraining.com
Sat Aug 12 13:05:05 EDT 2006
KraftDiner wrote:
> Hi I need help writing a python script that traverses (recursivly) a
> directory and its sub directories and processes all files in the
> directory. So at each directory if there are files in it I must build
> a list of those files and process them by exectuing a system command
> (exec?)
>
> Can some one tell me what methods to use to:
> a) Walk the directory tree
> b) execute a system command with parameters.
>
You're in luck. Both these are easy.
os.walk iterates through the hierarchy of directories and their contents
os.system executes any command given as a string (which you can build
however you want). Or you might use the newer "subprocess" module.
Gary Herron
> TIA.
>
>
More information about the Python-list
mailing list