<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unzip zip files in folders and subfolders with python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487073#M38029</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks Dan for your helps.&lt;/P&gt;&lt;P&gt;this code works fine:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import logging,zipfile&lt;/P&gt;&lt;P&gt;from pathlib import Path&lt;/P&gt;&lt;P&gt;from shutil import unpack_archive&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;zip_files = Path(r"C:\Project\layers").rglob("*.zip")&lt;/P&gt;&lt;P&gt;while True:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = next(zip_files)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except StopIteration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break # no more files&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except PermissionError:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logging.exception("permission error")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extract_dir = path.with_name(path.stem)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unpack_archive(str(path), str(extract_dir), 'zip')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 08 Feb 2015 06:48:04 GMT</pubDate>
    <dc:creator>Yaron_YosefCohen</dc:creator>
    <dc:date>2015-02-08T06:48:04Z</dc:date>
    <item>
      <title>Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487066#M38022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;Hello everyone,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;I try to unzip 150&amp;nbsp; zip files which contain shapefiles. All the zip files as different names, and they all spread in one big folder that divided to a lot of sub folders and sub sub folders.i want to extract each archive to separate folder with the same name as the original zip file name and also in the same place as the original zip file . &lt;SPAN style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;I'm working with arcview 10.3 and&lt;/SPAN&gt; my code is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import zipfile&amp;nbsp; 
import arcpy,os,os.path,sys
from arcpy import env

pattern = '*.zip'
folder = r"C:\Project\layers" 
files_process = []
for root,dirs,files in os.walk(r"C:\Project\layers"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filenames in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filenames == pattern:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; files_process.append(os.path.join(root, filenames))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zip.extract()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;After i run the code nothing happened.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt; Thanks in advance for any help on this.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:27:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487066#M38022</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2021-12-11T21:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with pythonafter i run</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487067#M38023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am confused...in your last line, you told Python to print 'zip' ... which it will do multiple times ... so as not to ruin the mystery...I assume that you wanted to have the zip file being printed rather than the word 'zip'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 10:30:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487067#M38023</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-02-05T10:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with pythonafter i run</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487068#M38024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks Dan i will change it now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 10:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487068#M38024</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-02-05T10:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487069#M38025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All you did in this thread &lt;A href="http://gis.stackexchange.com/questions/133210/unzip-files-in-folders-and-subfolders-with-python" title="http://gis.stackexchange.com/questions/133210/unzip-files-in-folders-and-subfolders-with-python"&gt;arcpy - Unzip files in folders and subfolders with python - Geographic Information Systems Stack Exchange&lt;/A&gt;&amp;nbsp; is simply remove the print statement...now nothing prints...as suggested there...did anything happen? did you explore the folders to see if anything was output?&amp;nbsp; If you did, then report the problem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE&lt;/P&gt;&lt;P&gt;this line&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14231355356678835" jivemacro_uid="_14231355356678835"&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; &lt;SPAN class="string"&gt;'unzip'&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;was originally&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14231355446861956 jive_text_macro" jivemacro_uid="_14231355446861956"&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; &lt;SPAN class="string"&gt;'zip'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;progress is being made&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 11:18:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487069#M38025</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-02-05T11:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487070#M38026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i checked all folders- nothing happend&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 11:34:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487070#M38026</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-02-05T11:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487071#M38027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;import os # needs to be added&lt;/P&gt;&lt;P&gt;os.listdir('c:/temp')&amp;nbsp; # to print files in a folder&lt;/P&gt;&lt;P&gt;Nothing becomes unzip since you don't have a variable called 'zip' so zip.extract() does nothing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 11:42:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487071#M38027</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-02-05T11:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487072#M38028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Research the module would help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import zipfile
zipfile.ZipFile('c:/source_folder/some.zip').extractall('c:/somefolder')&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:27:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487072#M38028</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T21:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unzip zip files in folders and subfolders with python</title>
      <link>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487073#M38029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks Dan for your helps.&lt;/P&gt;&lt;P&gt;this code works fine:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import logging,zipfile&lt;/P&gt;&lt;P&gt;from pathlib import Path&lt;/P&gt;&lt;P&gt;from shutil import unpack_archive&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;zip_files = Path(r"C:\Project\layers").rglob("*.zip")&lt;/P&gt;&lt;P&gt;while True:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = next(zip_files)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except StopIteration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break # no more files&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; except PermissionError:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logging.exception("permission error")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extract_dir = path.with_name(path.stem)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unpack_archive(str(path), str(extract_dir), 'zip')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Feb 2015 06:48:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unzip-zip-files-in-folders-and-subfolders-with/m-p/487073#M38029</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-02-08T06:48:04Z</dc:date>
    </item>
  </channel>
</rss>

