I'm using os.walk() to check a directory for redundant files and list them out. The pseudo-code looks something like this:
def checkPath(path):
do the for dirname, dirnames, filenames in os.walk(path) thing here...
pathList = ["path1", "path2"]
for each in pathList:
checkPath(each)
So this works fine the first run through, I get everything as expected, but on the next os.walk on the second path it just skips right on through...there's nothing in dirname, dirnames, filenames. I did some print statements to check things out, and it's entering the function, but not doing anything for the os.walk() part.
before making the os.walk() part a function to see if it would fix the problem, it was in a for loop inline with the main body. When I tried (just for fun) cleaning up the dirname, dirnames, filenames variables with del, on the second path when the cleanup came it said that the variable dirname did not exist...
So it looks like, whether within a function or not, the successive iterations of os.walk() arent populating...
ideas?
Thanks!
To add some working code as an example, something like this. It doesn't really matter what it's doing, just trying to get the os.walk to walk mult paths:
import os
def checkPath(path):
for dirname, dirnames, filenames in os.walk(path):
for filename in filenames:
print filename
pathList = ["c:\temp\folder1", "c:\temp\folder2"]
for path in pathList:
checkPath(path)
print "done"
It could be done this way (was trying to see if calling os.walk in a different way, like one of the other commenters suggested, might help), or it can be done inline, whatever works obviously...
thanks again all,
print 'checking', path, os.path.isdir(path). - tdelaney