Basically i have ZIP file for which i use a zipfile.ZipFile() object to represent. I'm trying to use namelist() to generate the file paths to where i will "copy" the files to. But the problem is i've got directories inside the ZIP aswell so i'd need to create them as well, but i don't know how to distinguish between what's meant to be a file and whats meant to be a directory.
The below generates and prints all the valid file paths.
- Code: Select all
zip_path=os.path.join("data","tmp","TEMP20091123sourceforge.net_projects_shellfire_files_shell_fire_v0_003_src.zip_download")
zip = zipfile.ZipFile(zip_path, "r", allowZip64=False)
self.__extractZip(os.getcwd(), zip)
def __extractZip(self, dir, zobj):
new_path = dir
for path in zobj.namelist():
for chunk in path.split("/"):
if chunk != "":
new_path = os.path.join(new_path, chunk)
print new_path
new_path = dir
return None
Example of what it returns
- Code: Select all
/home/oliver/Desktop/PackageUpdater/pgu
/home/oliver/Desktop/PackageUpdater/pgu/algo.py
/home/oliver/Desktop/PackageUpdater/pgu/ani.py
/home/oliver/Desktop/PackageUpdater/pgu/engine.py
/home/oliver/Desktop/PackageUpdater/pgu/fonts.py
/home/oliver/Desktop/PackageUpdater/pgu/gui
/home/oliver/Desktop/PackageUpdater/pgu/gui/app.py
/home/oliver/Desktop/PackageUpdater/changelog
/home/oliver/Desktop/PackageUpdater/controller.py
/home/oliver/Desktop/PackageUpdater/defs.py
/home/oliver/Desktop/PackageUpdater/license
/home/oliver/Desktop/PackageUpdater/main.py
/home/oliver/Desktop/PackageUpdater/player.py
/home/oliver/Desktop/PackageUpdater/readme
/home/oliver/Desktop/PackageUpdater/terrain
- Some files don't have an extension
- Some directories have periods in them
