os.walk trouble

Tim Chase python.list at tim.thechases.com
Thu Jun 1 17:27:21 CEST 2006


> but I am stuck with incorrect understanding of
> os.walk. I've tried:
> 
> root, dirs, files = os.walk(dirname)

os.walk returns an iteratable sequence of those tuples.  Thus, 
you want to have

for filepath, dirs, files in os.walk(dirname):
	#you're looking at the "dirs" and "files" in filepath
	print "Currently in %s" % filepath
	print "\t[Directories in %s]" % filepath
	print "\n\t".join(dirs)
	print "\t[Files in %s]" % filepath
	print "\n\t".join(files)
	print "=" * 50

HTH,

-tkc







More information about the Python-list mailing list