Jan-30-2018, 09:51 PM
I have some python code outside of a function that walks a directory tree. When the code detects a zip file (which could be nested), it calls a method called "ProcessZipFile(filePath)".
Inside that recursive function, if another zip file is found, it calls itself to process.
Here's the recursive function:
The strange thing is that when the code hits the lower processZipFile(name) line of code in the method above, instead of going back to the top and recursively processing, the code goes to the original call in the code that called this function.
main code below (not in a function):
.
.
.
I'm still new to Python, but I don't see what's going on. Why isn't the recursive call going back to the top of the function?
The recursive method does process the first zip file correctly.
Hope this posting is clear.
Thanks in advance,
Inside that recursive function, if another zip file is found, it calls itself to process.
Here's the recursive function:
1 2 3 4 5 6 7 8 |
# process zip files recursively if necessary def processZipFile(filePath): file = zipfile.ZipFile(filePath, "r" ) for name in file .namelist(): data = file .read(name) print (name) # of file if ( str (name).endswith( ".zip" )): processZipFile(name) |
main code below (not in a function):
.
.
.
1 2 |
if (filePath.endswith( "zip" )): processZipFile(filePath) |
The recursive method does process the first zip file correctly.
Hope this posting is clear.
Thanks in advance,