[Tutor] walking directories

Nick Lunt nick at javacat.f2s.com
Sat Jan 8 20:44:14 CET 2005


>>From: Ryan Davis [mailto:ryan at acceleration.net]
??
>>I think you want to be doing something like:
>>
>>>for r,d,f in os.walk('.'):
>>...	for filename in f:
>>...		print os.path.join(r,filename)
>>
>>I think that would give you the full path of every file, and then you can
open it, do a regex substitution or whatever close it and
>>keep going.
>>
>>From: Jacob Schmidt
>>
>>for root, dirs, files in os.walk(directory):
>>    for x in files:
>>        print os.path.join(root,x)

Thankyou Ryan and Jacob, I obviously did not read the docs for os.walk
correctly, many thanks.

>>Alan G.
>>personally I'd use find and sed in Linux, right tool
>>for the job etc..

Yes I could use *nix tools for the job, but I want to do it in python to see
if I can :)

Thanks again everyone for your help.

Nick .



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 06/01/2005



More information about the Tutor mailing list