os.walk iteration not walking in Python -


i'm using os.walk() check directory redundant files , list them out. pseudo-code looks this:

def checkpath(path):     dirname, dirnames, filenames in os.walk(path) thing here...  pathlist = ["path1", "path2"]  each in pathlist:     checkpath(each) 

so works fine first run through, expected, on next os.walk on second path skips right on through...there's nothing in dirname, dirnames, filenames. did print statements check things out, , it's entering function, not doing os.walk() part.

before making os.walk() part function see if fix problem, in loop inline main body. when tried (just fun) cleaning dirname, dirnames, filenames variables del, on second path when cleanup came said variable dirname did not exist...

so looks like, whether within function or not, successive iterations of os.walk() arent populating...

ideas?

thanks!


to add working code example, this. doesn't matter it's doing, trying os.walk walk mult paths:

import os  def checkpath(path):     dirname, dirnames, filenames in os.walk(path):         filename in filenames:             print filename  pathlist = ["c:\temp\folder1", "c:\temp\folder2"]  path in pathlist:     checkpath(path)  print "done" 

it done way (was trying see if calling os.walk in different way, 1 of other commenters suggested, might help), or can done inline, whatever works obviously...

thanks again all,

your code works me, if use actual paths on system refer non-empty directories.

i suspect might have issue line...

pathlist = ["c:\temp\folder1", "c:\temp\folder2"] 

...since both \t , \f valid escape sequences.

try...

pathlist = ["c:\\temp\\folder1", "c:\\temp\\folder2"] 

...and if that's not problem, cite actual code you're using.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -