Problem opening files while using os.path.walk
holger krekel
pyth at devel.trillke.net
Thu Nov 28 16:56:43 EST 2002
R. Arens wrote:
> Hi. I'm writing what should be a simple function that will walk a
> directory structure, opening and joining all files within the
> directory tree into a single huge file. I'm using os.path.walk and
> testing the list of files returned to the function specified in walk
> to make sure that each file is actually a file as opposed to another
> directory - herein lies the problem. The function isn't seeing
> _anything_ as a file, and is just skipping it. This one has me quite
> perplexed, and I'd appreciate any help anyone can offer. Thanks!
>
> Code follows....
>
> import os, sys
>
> def walkJoin(out, dirname, names):
> print "Current directory: " + dirname
> names.sort()
> for name in names:
you have to do
name = os.path.join(dirname, name)
to actually have the full path.
holger
More information about the Python-list
mailing list