Problem with directory recursion!
rcdailey at gmail.com
Fri Aug 17 20:19:13 CEST 2007
Here's part of the output that's incorrect:
Notice that the file BYOS_C.entity.xml is showing up as a file in the
directory W_BoomerEdge. This file does not exist in this folder, but yet in
a different folder. The output is consistent with the 'print' statements you
will see in the function I posted earlier.
On 8/17/07, Robert Dailey <rcdailey at gmail.com> wrote:
> I've created a function that is used to recurse a directory tree in
> Windows XP using os.walk(). For the most part it works, however in some
> instances the data is incorrect and I'm getting invalid sub-directory paths.
> Here's the function:
> def __doSearch( root_dir, sub_path, restype, ext ):
> print sub_path
> # Searches the specified directory and generates a
> # list of files to preload.
> complete_path = osp.normpath( osp.join( root_dir, sub_path ) )
> for root, dirs, files in os.walk( complete_path ):
> # Record the list of file hash ID's
> for file in files:
> split = __resType( file )
> if split == restype:
> # print sub_path
> print "\t", file
> __appendResource( ext, sub_path, split )
> # Remove .svn subdirectories; we don't walk these.
> if ".svn" in dirs:
> dirs.remove( ".svn" )
> # Recurse child directories
> for dir in dirs:
> __doSearch( root_dir, osp.join( sub_path, dir ), restype, ext
> Does anyone see anything immediately suspicious about the code? I'm
> assuming that in Python, every time a function is called recursively it gets
> its own copy of local variables. For some reason the sub_path variable isn't
> consistent depending on where I use it. For example, if you notice the print
> call at the very start of the function, it will output something like
> "models/ships". However, after passing it into __appendResource(), it
> appears to be just "models".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list