<?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: Zip all Shapefiles in a folder into their own zip folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568219#M73335</link>
    <description>&lt;P&gt;They need to be wrapped in two parentheses: One for the endswith() and the other to feed both of them to the endswith() at the same time.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;if not f.endswith(('.lock', '.shp')):&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;not&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;if not f.endswith('.lock', '.shp'):&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Right now it thinks you fed it two arguments when you're really trying to feed it one.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2024 22:41:11 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-12-12T22:41:11Z</dc:date>
    <item>
      <title>Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568138#M73332</link>
      <description>&lt;P&gt;I need to take a folder that contains multiple shapefiles and then zip them all into their own individual zip file.&amp;nbsp; I found this script on a REALLY old post and it does what I'm looking for.&amp;nbsp; However, I'm running into one issue.&amp;nbsp; Before the zip section of the script, the python steps through several other steps of the shapefiles being exported to this location with certain criteria.&amp;nbsp; So what happens is I get the shapefiles, but each shapefile contains a lock file.&amp;nbsp; When the script starts for the zip, it starts to execute from top to bottom in the folder, but once it hits the first lock file it then fails.&amp;nbsp; I have this in Notebook in a Pro Project.&amp;nbsp; Once I close the Pro Project the lock files disappear, but as soon as I reopen the Pro Project the lock is reapplied because even though I don't have a map open, when I run my export features script it automatically adds it to the default map so it places a lock on it.&amp;nbsp; Is there a way to make the below zip script ignore any lock files or release all shapefile lock files in a folder?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
from os import path as p
import zipfile
arcpy.overwriteOutput = True


def ZipShapes(path, out_path):
    arcpy.env.workspace = path
    shapes = arcpy.ListFeatureClasses()

    # iterate through list of shapefiles
    for shape in shapes:
        name = p.splitext(shape)[0]
        print (name)
        zip_path = p.join(out_path, name + '.zip')
        zip = zipfile.ZipFile(zip_path, 'w', compression=zipfile.ZIP_DEFLATED)
        zip.write(p.join(path,shape), shape)
        for f in arcpy.ListFiles('%s*' %name):
            if not f.endswith('.shp'):
                zip.write(p.join(path,f), f)
        print ("All files written to %s" %zip_path)
        zip.close()

if __name__ == '__main__':

    path = r"Z:\General\Projects\Engineering\SubSurface Mapping\DataExport\Updates"
    outpath = r"Z:\General\Projects\Engineering\SubSurface Mapping\DataExport\Updates\ZipFiles"

    ZipShapes(path, outpath)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 21:30:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568138#M73332</guid>
      <dc:creator>LindseyStone</dc:creator>
      <dc:date>2024-12-12T21:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568146#M73333</link>
      <description>&lt;P&gt;try changing line 19 to&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;if not f.endswith(('.lock', '.shp')):&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That will make it ignore ".shp" and lock files&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 21:38:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568146#M73333</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-12-12T21:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568216#M73334</link>
      <description>&lt;P&gt;I get the below when I change that line of code.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LindseyStone_0-1734043033983.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/121666iF5A40C77DF5A830E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LindseyStone_0-1734043033983.png" alt="LindseyStone_0-1734043033983.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 22:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568216#M73334</guid>
      <dc:creator>LindseyStone</dc:creator>
      <dc:date>2024-12-12T22:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568219#M73335</link>
      <description>&lt;P&gt;They need to be wrapped in two parentheses: One for the endswith() and the other to feed both of them to the endswith() at the same time.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;if not f.endswith(('.lock', '.shp')):&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;not&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;if not f.endswith('.lock', '.shp'):&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Right now it thinks you fed it two arguments when you're really trying to feed it one.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 22:41:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568219#M73335</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-12-12T22:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568222#M73336</link>
      <description>&lt;P&gt;Missed the double brackets. on your first post.&amp;nbsp; That worked!!!&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 22:44:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568222#M73336</guid>
      <dc:creator>LindseyStone</dc:creator>
      <dc:date>2024-12-12T22:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Zip all Shapefiles in a folder into their own zip folder</title>
      <link>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568258#M73337</link>
      <description>&lt;P&gt;You can also config Pro to Not add the output layers to the map, then shouldn't lock them. (not tested with shapefiles).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RhettZufelt_0-1734047372030.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/121677i2C38C00308E91440/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RhettZufelt_0-1734047372030.png" alt="RhettZufelt_0-1734047372030.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Could also just run it standalone outside of Pro.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 23:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zip-all-shapefiles-in-a-folder-into-their-own-zip/m-p/1568258#M73337</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-12-12T23:51:27Z</dc:date>
    </item>
  </channel>
</rss>

