[Tutor] making a function work with os.path.walk()

Alan Gauld alan.gauld at blueyonder.co.uk
Sat Feb 14 20:16:48 EST 2004


CHristopher,

This is a guess based on a quick scan of the code and error.

> def get_size(n,dir,files):
>     files_of_size = {}; sizes = [];
>     biggest_files = []; files_sizes = [];
>     files = map(os.path.join,[dir] * len(files),files)
>     files = filter(lambda x: not os.path.isdir(x)
>                    and not os.path.islink(x),
> os.listdir(dir))

I think this will prepend the top level(starting) directory
to the filenames - even for the subdirectories.

Thus it contains

foo/f1
foo/f2
foo/g1   # should be  foo/subdir/g1

then when you try to act on g1 it can't find it because
the path is wrong. I think you might need to keep track of the current
path...

But I may be barking up the wrong tree, its very late...

Alan G.




More information about the Tutor mailing list