Recurse Directories and process files in directory

vasudevram vasudevram at gmail.com
Sat Aug 12 12:58:03 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.
>
> TIA.

Hi,
Try os.walk().
Don't remember the syntax right now, should be straightforward. Check
the standard Python docs that come with your Python installation. Or
start python and do:

import os
print os.walk.__doc__

And executing a system comand is os.system(...).

Caveat: there can be security risks with system(). Depends how you use
it and who you let use it with what arguments. Similar to risks with
CGI forms.

HTH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vasudev Ram
xtopdf - PDF creation/converson toolkit:
    http://www.dancingbison.com/products.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




More information about the Python-list mailing list