<?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: Extract Zip files to one folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551647#M43081</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are really getting muddled in retaining your paths.&amp;nbsp; Might I suggest that you do the following&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;collect the filenames into a list first&lt;/LI&gt;&lt;LI&gt;remove or rename any duplicates&lt;/LI&gt;&lt;LI&gt;process the filenames in the previous step last&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;putting all this into a function will help.&amp;nbsp; Have a look a my blog post on finding files with a particular file extension.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/54654"&gt;Before I forget ... # 4 ... Where did that script go?&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Jun 2015 15:19:33 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-06-04T15:19:33Z</dc:date>
    <item>
      <title>Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551641#M43075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;Continuously to &lt;A href="https://community.esri.com/thread/159332" target="_blank"&gt;Unzip files from directory tree&lt;/A&gt; ,when i try to&amp;nbsp; extract zip files that contain files with same names in it to one folder , some files got lost because &lt;SPAN style="color: #3e3e3e; font-family: Arial; font-size: 16px;"&gt;duplication names&lt;/SPAN&gt;. I use this code (i work with python 2.7.8 and arcmap 10.3):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;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):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in fnmatch.filter(files, pattern):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(os.path.join(root, filename))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outpath = r"C:\Project\gis\layers\taba\new"&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print root
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print filename
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zipfile.ZipFile(os.path.join(root, filename)).extractall(r"C:\Project\gis\layers\taba\new")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know how to &lt;SPAN style="color: #3e3e3e; font-family: Arial; font-size: 10pt;"&gt;overcome that issue &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3e3e3e; font-family: Arial; font-size: 10pt;"&gt;Thank for any help&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:51:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551641#M43075</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2021-12-11T23:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551642#M43076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Under your outpath assignment put an if statement.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-family: arial,helvetica,sans-serif;"&gt;for root, dirs, files &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; os.walk(rootPath):&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; fnmatch.filter(files, pattern):&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(os.path.join(root, filename))&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outpath = r&lt;SPAN class="string"&gt;"C:\Project\gis\layers\taba\new"&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="k"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for&lt;/SPAN&gt; &lt;SPAN class="n"&gt;files&lt;/SPAN&gt; &lt;SPAN class="ow"&gt;in&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ListFiles&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;outpath&lt;SPAN class="p"&gt;):&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;CODE&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If files &amp;lt;&amp;gt; filename:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print root&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print filename&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zipfile.ZipFile(os.path.join(root, filename)).extractall(r&lt;/SPAN&gt;&lt;SPAN class="string"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;"C:\Project\gis\layers\taba\new") &lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or something like that anyway &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 14:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551642#M43076</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-03T14:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551643#M43077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get :&lt;/P&gt;&lt;P&gt;&lt;IMG alt="1.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/106351_1.jpg" style="height: auto;" /&gt;&lt;IMG alt="2.jpg" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/106568_2.jpg" style="width: 620px; height: 291px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 11:55:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551643#M43077</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2015-06-04T11:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551644#M43078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;your&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt; if&lt;/STRONG&gt; &lt;/SPAN&gt;is capitalized&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 11:58:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551644#M43078</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-06-04T11:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551645#M43079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks-i've changed that now- nothing happened&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; ================================ RESTART ================================
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:52:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551645#M43079</guid>
      <dc:creator>Yaron_YosefCohen</dc:creator>
      <dc:date>2021-12-11T23:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551646#M43080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It completed, but your your expression for your if statement was never true, so nothing printed.&amp;nbsp; It looks like you are reassigning your variable "files" multiple times?&amp;nbsp; Try a different variable name other than "files" for your third for loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 14:32:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551646#M43080</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2015-06-04T14:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Zip files to one folder</title>
      <link>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551647#M43081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are really getting muddled in retaining your paths.&amp;nbsp; Might I suggest that you do the following&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;collect the filenames into a list first&lt;/LI&gt;&lt;LI&gt;remove or rename any duplicates&lt;/LI&gt;&lt;LI&gt;process the filenames in the previous step last&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;putting all this into a function will help.&amp;nbsp; Have a look a my blog post on finding files with a particular file extension.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/54654"&gt;Before I forget ... # 4 ... Where did that script go?&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 15:19:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extract-zip-files-to-one-folder/m-p/551647#M43081</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-06-04T15:19:33Z</dc:date>
    </item>
  </channel>
</rss>

