<?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 Zip a file geodatabase using ArcPy or Zipfile library in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388286#M30687</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anybody have a good method of doing this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried using the zipfile python library but am utterly confused on how to do it for a file geodatabase since it's not exactly a directory/file structure. My folder structure looks like so, I want to zip up the folder/geodatabase outlined in red:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="427086" alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/427086_Capture.JPG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried this (all the indentation is correct in my script, don't know why GeoNet is changing it upon publishing the question):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; zipfile

&lt;SPAN class="comment token"&gt;#Creates the empty zip file and opens it for writing&lt;/SPAN&gt;
myzipfile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; zipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ZipFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase\MyZip.zip"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; zipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ZIP_DEFLATED&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; root&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dirs&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; files &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;walk&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; root &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase\HabitatData.gdb"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; files&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 myzipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;root&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; file&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried using shutil.make_archive and for some reason instead of zipping up my file geodatabase it zips up my python script file which is completely bewildering as I have no idea how it would even get the path to the script file...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a TypeError on the last line that says "object of type 'type' has no len()"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:50:12 GMT</pubDate>
    <dc:creator>MKF62</dc:creator>
    <dc:date>2021-12-11T17:50:12Z</dc:date>
    <item>
      <title>Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388286#M30687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anybody have a good method of doing this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried using the zipfile python library but am utterly confused on how to do it for a file geodatabase since it's not exactly a directory/file structure. My folder structure looks like so, I want to zip up the folder/geodatabase outlined in red:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="427086" alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/427086_Capture.JPG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried this (all the indentation is correct in my script, don't know why GeoNet is changing it upon publishing the question):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; zipfile

&lt;SPAN class="comment token"&gt;#Creates the empty zip file and opens it for writing&lt;/SPAN&gt;
myzipfile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; zipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ZipFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase\MyZip.zip"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; zipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ZIP_DEFLATED&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; root&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dirs&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; files &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;walk&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; root &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D:\GIS_Testing\HabitatDbase\HabitatData.gdb"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; files&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 myzipfile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;root&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; file&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried using shutil.make_archive and for some reason instead of zipping up my file geodatabase it zips up my python script file which is completely bewildering as I have no idea how it would even get the path to the script file...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a TypeError on the last line that says "object of type 'type' has no len()"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:50:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388286#M30687</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-11T17:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388287#M30688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Should it be 'f' rather than 'file' in the last line?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:24:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388287#M30688</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2018-11-02T18:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388288#M30689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hahaha, seriously, of course it's just a typo. Thank you!! I'll leave the thread up because I couldn't find any good examples on how to zip up a file geodatabase in python on GeoNet. Maybe it'll help someone later...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:30:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388288#M30689</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2018-11-02T18:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388289#M30690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/289244"&gt;Michelle Mathias&lt;/A&gt;‌ code mangling still today... it is going to get ugly until they fix it &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:40:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388289#M30690</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-11-02T18:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388290#M30691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agreed, now that the mangling is affecting discussions in addition to blogs, the impacts will be much more significant.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:46:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388290#M30691</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-11-02T19:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388291#M30692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just&amp;nbsp;put some pressure on the&amp;nbsp;vendor&amp;nbsp;to get us a fix soon.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:58:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388291#M30692</guid>
      <dc:creator>MichelleMathias</dc:creator>
      <dc:date>2018-11-02T19:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388292#M30693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is one of the only examples I can find of zipping up a .gdb with python, however when I try to use this method,(accounting for the typo in the last line) my new zip file contains the entire folder structure leading up to the .gdb. Anyone have an idea of how to just zip up the .gdb file?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:44:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388292#M30693</guid>
      <dc:creator>AaronKoelker</dc:creator>
      <dc:date>2019-10-24T14:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388293#M30694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As usual, seconds after posting a question -- I get it to work. However I used shutil.make_archive instead of the above ZipFile method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;shutil.make_archive(zipfilename, 'zip', fgdb)‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;zipfilename = filename of your new zip, plus the path ("D:/MyFolder/ExampleFolder/thenameofmynewzip"), leave off the .zip file extension&lt;/LI&gt;&lt;LI&gt;fgdb = the file geodatabase you want to zip ("D:/MyFolder/ExampleFolder/MyFGDB.gdb")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: Actually, while the above code technically works, it won't be a good solution if you're trying to zip up the fgdb for uploading to ArcGIS Online. Instead, have &lt;EM&gt;fgdb&lt;/EM&gt; point to the folder that contains the MyFGDB.gdb file, rather than the .gdb file itself. Otherwise you'll get an error when uploading to AGO. You'll also want separate the the new zipfile and the fgdb into their own folders, or add code to grab the fgdb specifically (similar to what the original post is doing). If not, you'll get an empty zip within your zip since it creates the new zip file first before adding in your .gdb, looks like. I'm sure someone else has a more elegant solution to this bit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Oct 2019 14:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388293#M30694</guid>
      <dc:creator>AaronKoelker</dc:creator>
      <dc:date>2019-10-24T14:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388294#M30695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The '.gdb' of a file geodatabase is a directory, not a file. The file geodatabase is the directory and all the files below it (except the lock files&amp;nbsp;-- you can keep those out).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Oct 2019 18:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/388294#M30695</guid>
      <dc:creator>VinceAngelo</dc:creator>
      <dc:date>2019-10-25T18:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1178995#M64684</link>
      <description>&lt;P&gt;Old post but figured I'd post my solution incase it helps anyone else. This function will zip the geodatabase and skip any lock files. I was trying to implement the zip in a larger codebase and kept running into locks.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;zipGDB&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;inputGDB&lt;/SPAN&gt;&lt;SPAN&gt;):&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    gdbFile &lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;inputGDB&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    outFile &lt;SPAN&gt;= &lt;/SPAN&gt;gdbFile&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;:-&lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;] + &lt;/SPAN&gt;&lt;SPAN&gt;'.zip'&lt;BR /&gt;&lt;/SPAN&gt;    gdbName &lt;SPAN&gt;= &lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;path&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;basename&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;gdbFile&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;with &lt;/SPAN&gt;zipfile&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;ZipFile&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;outFile&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;mode&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;'w'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;compression&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;zipfile&lt;SPAN&gt;.&lt;/SPAN&gt;ZIP_DEFLATED&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;allowZip64&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;SPAN&gt;as &lt;/SPAN&gt;myzip&lt;SPAN&gt;:&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;for &lt;/SPAN&gt;f &lt;SPAN&gt;in &lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;listdir&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;gdbFile&lt;SPAN&gt;):&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;if &lt;/SPAN&gt;f&lt;SPAN&gt;[-&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;:] != &lt;/SPAN&gt;&lt;SPAN&gt;'.lock'&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;BR /&gt;&lt;/SPAN&gt;                myzip&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;write&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;path&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;gdbFile&lt;SPAN&gt;, &lt;/SPAN&gt;f&lt;SPAN&gt;), &lt;/SPAN&gt;gdbName &lt;SPAN&gt;+ &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;\\&lt;/SPAN&gt;&lt;SPAN&gt;' &lt;/SPAN&gt;&lt;SPAN&gt;+ &lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;path&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;basename&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;f&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    print&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Completed zipping: {}'&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;format&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;gdbFile&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 14:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1178995#M64684</guid>
      <dc:creator>tigerwoulds</dc:creator>
      <dc:date>2022-06-01T14:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1241291#M66268</link>
      <description>&lt;P&gt;Thanks for adding this key distinction. Saved me a lot of time.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 19:09:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1241291#M66268</guid>
      <dc:creator>DAVIDWADSWORTH_LVVWD</dc:creator>
      <dc:date>2022-12-14T19:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1241292#M66269</link>
      <description>&lt;P&gt;Thanks for sharing.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 19:09:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1241292#M66269</guid>
      <dc:creator>DAVIDWADSWORTH_LVVWD</dc:creator>
      <dc:date>2022-12-14T19:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1299967#M67980</link>
      <description>&lt;P&gt;Since this took me &lt;EM&gt;much&amp;nbsp;&lt;/EM&gt;longer to figure out than I care to admit:&lt;/P&gt;&lt;P&gt;The sample provided by TigerWoulds results in a copy of the inputGDB within a zipped folder of the same name. If you want to create a zipped copy &lt;EM&gt;without&lt;/EM&gt; that nesting then remove&lt;/P&gt;&lt;PRE&gt;gdbName &lt;SPAN&gt;+ &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;\\&lt;/SPAN&gt;&lt;SPAN&gt;' &lt;/SPAN&gt;&lt;SPAN&gt;+ &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;from the line&lt;/P&gt;&lt;PRE&gt;myzip&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;write&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;path&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;gdbFile&lt;SPAN&gt;, &lt;/SPAN&gt;f&lt;SPAN&gt;), &lt;/SPAN&gt;gdbName &lt;SPAN&gt;+ &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;\\&lt;/SPAN&gt;&lt;SPAN&gt;' &lt;/SPAN&gt;&lt;SPAN&gt;+ &lt;/SPAN&gt;os&lt;SPAN&gt;.&lt;/SPAN&gt;path&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;basename&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;f&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 20:03:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1299967#M67980</guid>
      <dc:creator>danashney</dc:creator>
      <dc:date>2023-06-15T20:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1392688#M70027</link>
      <description>&lt;P&gt;Reviving an older thread, but there aren't too many helpful resources online about this topic...&lt;/P&gt;&lt;P&gt;I had issues utilizing tigerwoulds' script, so I tweaked the function a bit:&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="lia-align-justify"&gt;&amp;nbsp;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;zip_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;input_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;output_zip&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-align-justify"&gt;&lt;PRE&gt;&lt;SPAN&gt;def&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zip_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;input_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;output_zip&lt;/SPAN&gt;&lt;SPAN&gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;     #&amp;nbsp;Create&amp;nbsp;a&amp;nbsp;zip&amp;nbsp;file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;     with&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zipfile&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;ZipFile&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;output_zip&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'w'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zipf&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;          #&amp;nbsp;Iterate&amp;nbsp;over&amp;nbsp;all&amp;nbsp;files&amp;nbsp;in&amp;nbsp;the&amp;nbsp;geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;          for&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;root&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;dirs&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;files&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;os&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;walk&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;input_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;               for&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;file&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;files&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;                    #&amp;nbsp;Add&amp;nbsp;each&amp;nbsp;file&amp;nbsp;to&amp;nbsp;the&amp;nbsp;zip&amp;nbsp;file&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;                    file_path&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;os&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;path&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;root&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;file&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;                    if&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;file&lt;/SPAN&gt;&lt;SPAN&gt;[-&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;:]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;!=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'.lock'&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;                         zipf&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;write&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;file_path&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;os&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;path&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;relpath&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;file_path&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;input_geodatabase&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;BR /&gt;&lt;BR /&gt;#input_geodatabase&amp;nbsp;=&amp;nbsp;r"C:\Users\myfile.gdb"&lt;BR /&gt;#output_zip&amp;nbsp;=&amp;nbsp;r"C:\Users\myoutputfile.zip"&lt;BR /&gt;#zip_geodatabase(input_geodatabase,&amp;nbsp;output_zip)&lt;BR /&gt; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 07 Mar 2024 17:35:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1392688#M70027</guid>
      <dc:creator>patrick_shp</dc:creator>
      <dc:date>2024-03-07T17:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1393541#M70030</link>
      <description>&lt;P&gt;Slight addendum:&lt;/P&gt;&lt;P&gt;You can't zip the .gdb file directly and upload to portal using this script. It must first be added to a subfolder by itself. So that means that &lt;STRONG&gt;input_geodatabase&lt;/STRONG&gt; points to something like&amp;nbsp;&lt;SPAN&gt;r"C:\Users\parent_folder", where "parent_folder" contains only the .gdb file. Hope that makes sense!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 03:13:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1393541#M70030</guid>
      <dc:creator>patrick_shp</dc:creator>
      <dc:date>2024-03-09T03:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1601268#M73976</link>
      <description>&lt;LI-CODE lang="python"&gt;shutil.make_archive(zipfilename, 'zip', root_dir = r"C:\folder\path\containing_fgdb", base_dir = "file_gdb_name.gdb")‍‍‍‍‍‍‍&lt;/LI-CODE&gt;&lt;P&gt;This should avoid the need to have your file geodatabase in it's own subfolder before zipping, which I think is required in the above solution.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 13:41:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1601268#M73976</guid>
      <dc:creator>AndyFairbairn</dc:creator>
      <dc:date>2025-04-01T13:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Zip a file geodatabase using ArcPy or Zipfile library</title>
      <link>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1629600#M74472</link>
      <description>&lt;P&gt;This was super helpful! But one caution for future users, if you copy and paste the script the last line may cause an invalid character error. For some reason the last line from this discussion page contained a Zero-width joiner, unicode "U+200D".&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jul 2025 19:57:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-a-file-geodatabase-using-arcpy-or-zipfile/m-p/1629600#M74472</guid>
      <dc:creator>ARyanWADNR</dc:creator>
      <dc:date>2025-07-02T19:57:02Z</dc:date>
    </item>
  </channel>
</rss>

