Hi everyone,
Continuously to Unzip files from directory tree ,when i try to extract zip files that contain files with same names in it to one folder , some files got lost because duplication names. I use this code (i work with python 2.7.8 and arcmap 10.3):
import zipfile,fnmatch,os # EXTRACT ALL ZIP FILES IN DIRECTORY TREE TO ONE SPECIFIC FOLDER rootPath = r"C:\Project" pattern = '*.zip' for root, dirs, files in os.walk(rootPath): for filename in fnmatch.filter(files, pattern): print(os.path.join(root, filename)) outpath = r"C:\Project\gis\layers\taba\new" print root print filename zipfile.ZipFile(os.path.join(root, filename)).extractall(r"C:\Project\gis\layers\taba\new")
I don't know how to overcome that issue
Thank for any help
Under your outpath assignment put an if statement.
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
print(os.path.join(root, filename))
outpath = r"C:\Project\gis\layers\taba\new"
for files in arcpy.ListFiles(outpath😞
If files <> filename:
print root
print filename
zipfile.ZipFile(os.path.join(root, filename)).extractall(r"C:\Project\gis\layers\taba\new")
Or something like that anyway
I get :
your if is capitalized
thanks-i've changed that now- nothing happened
>>> ================================ RESTART ================================ >>> >>>
It completed, but your your expression for your if statement was never true, so nothing printed. It looks like you are reassigning your variable "files" multiple times? Try a different variable name other than "files" for your third for loop.
You are really getting muddled in retaining your paths. Might I suggest that you do the following
putting all this into a function will help. Have a look a my blog post on finding files with a particular file extension.