[Tutor] How can I make a python script go directory by directory and excecute on files of choice
singletoned at gmail.com
Wed Jan 11 14:48:11 CET 2006
On 11/01/06, Liam Clarke <ml.cyresse at gmail.com> wrote:
> Hi Srinivas -
> For walking a directory, you can use os.walk() or os.path.walk(), but
> I prefer the path module here -
The Path module is excellent, but it's walk still doesn't take into
account the depth of the current file in the folder structure.
If you need that, I wrote (with Kent's help) a simple script that will
take it into account (you need the Path module above for it to work).
def traverse(directory, function, depth=0):
thedir = path.path(directory)
for item in thedir.files():
for item in thedir.dirs():
It can be used like:
def doprint(item, depth):
Hope it's helpful to someone.
More information about the Tutor