'Get full file path of a zip file based on the file extension inside of that zip file python
I am attempting to grab the file path of a file within a zipped file. For example, I have this file: E:\API_creation\upload\TestingData.zip\TestingData.gdb. I would like to create a python script that will grab the file path "E:\API_creation\upload\TestingData.zip." However, when I run the following script, I am left with the following output: "E:\API_creation\upload\TestingData.gdb."
gdbfiles = []
shpfiles = []
csvfiles = []
jsonfiles = []
zipfiles = []
for root, dirs, files in os.walk (folder):
for file in files:
if file.endswith(".zip"):
zipfiles.append(os.path.join(root, file))
elif file.endswith(".csv"):
csvfiles.append(os.path.join(root, file))
elif file.endswith(".json"):
jsonfiles.append(os.path.join(root, file))
else:
pass
#find zipped gdb files
gdb_dirs = []
for i in zipfiles:
zip_f = ZipFile(i)
for f in zip_f.namelist():
zinfo = zip_f.getinfo(f)
if zinfo.is_dir():
r_dir = f.split('/')
r_dir = r_dir[0]
if r_dir not in gdb_dirs:
gdb_dirs.append(r_dir)
for i in gdb_dirs:
if i.endswith(".gdb"):
gdbfiles.append(os.path.join(root, i))
else:
pass
print(gdbfiles)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
