<?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: Create &amp;quot;Zip&amp;quot; file in Model Builder in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124883#M336</link>
    <description>&lt;P&gt;I attempted this change to:&amp;nbsp; "for ff in glob.glob(name + "*"):"&lt;/P&gt;&lt;P&gt;and I had the same result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could this be stuffing the zipfile that it is creating into the zipfile that it is creating, creating a loop of sorts?&lt;/P&gt;</description>
    <pubDate>Fri, 10 Dec 2021 15:45:41 GMT</pubDate>
    <dc:creator>Syvertson</dc:creator>
    <dc:date>2021-12-10T15:45:41Z</dc:date>
    <item>
      <title>Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124320#M320</link>
      <description>&lt;P&gt;I have a model builder process that will create a shapefile, that later is retrieved by another process.&amp;nbsp; The other process requires a zip file input.&amp;nbsp; Is there any way I can zip up these files within model builder?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 13:09:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124320#M320</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2023-06-21T13:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124384#M321</link>
      <description>&lt;P&gt;Hello Matthew,&lt;/P&gt;&lt;P&gt;I have a similar process but it is handled using a combination of a python script to prepare the data and then a batch file script to zip the contents of the folder.&amp;nbsp; I can share it with you if you like.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:00:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124384#M321</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-12-09T16:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124392#M322</link>
      <description>&lt;P&gt;You can do this using the Calculate Value tool, with a python function that uses &lt;A href="https://docs.python.org/3/library/glob.html" target="_self"&gt;glob&lt;/A&gt; and&amp;nbsp;&amp;nbsp;&lt;A href="https://docs.python.org/3/library/zipfile.html" target="_self"&gt;zipfile&lt;/A&gt;. You may want to run Parse Path first to get the info you need to create the zip (folder, shapefile root name).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:05:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124392#M322</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-09T16:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124424#M323</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zipshape.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/29294i997307E6170C573C/image-size/large?v=v2&amp;amp;px=999" role="button" title="zipshape.png" alt="zipshape.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;UPDATE: added check to loop to avoid trying to write the zipfile into itself and causing an infinite loop (!) (discussed downthread)&amp;nbsp;&amp;nbsp;&lt;BR /&gt;UPDATE: this function requires the two inputs folder (path to the shapefile) and name (shapefilename, for example if your shapefile is foo.shp, the name should be foo (without the extension)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import glob
import zipfile
def zipshape(folder, name):
    os.chdir(folder)
    zipname = name + ".zip"
    with zipfile.ZipFile(zipname, "w") as newzip:
        for ff in glob.glob(name + ".*"):
            if ff[-4:] != "lock" and ff != zipname: 
                newzip.write(ff)
    return os.path.join(folder,zipname)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:57:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124424#M323</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2022-01-21T17:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124626#M324</link>
      <description>&lt;P&gt;I am not yet great at python, so simple is better.&amp;nbsp; If I already know what the full path and shapefile name is always going to be, how would this look simplified?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 21:55:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124626#M324</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-09T21:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124629#M325</link>
      <description>&lt;P&gt;See below for the batch file script that I use to zip up the files. You will have to download 7Zip software to make it work.&amp;nbsp; Put this in a text file in notepad and then save it as a .bat.&amp;nbsp; I run it in Windows Task scheduler behind the script that prepares the text files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;:: Zip TxtFiles in DATA\TEXT folder&lt;BR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/464769"&gt;@echo&lt;/a&gt; ON&lt;/P&gt;&lt;P&gt;SET SourceDir=K:\GIS_UPDATE\DATA\TXT*.txt&lt;BR /&gt;SET DestDir=K:\GIS_UPDATE\DATA\TXT\MCPAEXTRACT.zip&lt;/P&gt;&lt;P&gt;CD /D "C:\Program Files\7-Zip"&lt;BR /&gt;7z.exe a "%DestDir%" "%SourceDir%"&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 22:00:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124629#M325</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-12-09T22:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124669#M326</link>
      <description>&lt;P&gt;Honestly I can't think of an simpler way to do this.&lt;/P&gt;&lt;P&gt;This is a plug and play python function, you don't need to edit it at all, just create a calculate value tool and paste the code in the code block, and make sure the variables (inside the %) match the model variables that have your folder and shapefile name. The function doesn't care as long as you give it the correct folder and shapefile root name, which is easily found with Parse Path. I suppose you could enter your folder and shapefile name directly in the Calculate Value tool expression in place the model variables...but Parse Path makes it pretty easy to avoid having to hard-code it.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 23:08:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124669#M326</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-09T23:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124842#M327</link>
      <description>&lt;P&gt;OK.&amp;nbsp; I will try it and let you know how it goes.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 14:01:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124842#M327</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T14:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124843#M328</link>
      <description>&lt;P&gt;I want to stay in model builder, but if the other solution does not work, I will try this one.&amp;nbsp; Thank you for your contribution.&amp;nbsp; I am sure it will benefit someone, whether its me or another down the road.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 14:02:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124843#M328</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T14:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124844#M329</link>
      <description>&lt;P&gt;Let me know if you try my method.&amp;nbsp; I have been doing this same workflow for over 3 years with no issues.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 14:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124844#M329</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-12-10T14:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124865#M331</link>
      <description>&lt;P&gt;The process "calculate values" seems to have created the zip file just fine, but the model builder is stuck on the step.&amp;nbsp; The zip file was created and has not changed file size for about 20 minutes.&amp;nbsp; See screen shot:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MatthewSyvertson_0-1639148893340.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/29397i6867A06F7E4A7CD2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MatthewSyvertson_0-1639148893340.png" alt="MatthewSyvertson_0-1639148893340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I can't understand what would hang it up.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:09:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124865#M331</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T15:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124868#M332</link>
      <description>&lt;P&gt;Update to this:&amp;nbsp; I force killed the process through task manager, and the file size had grown huge, and it was an invalid file when I tried to open.&amp;nbsp; See screen shot:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MatthewSyvertson_0-1639149509376.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/29398iDB4446F718082AB8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MatthewSyvertson_0-1639149509376.png" alt="MatthewSyvertson_0-1639149509376.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124868#M332</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T15:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124875#M333</link>
      <description>&lt;P&gt;That's really weird as it worked for me - but my test model didn't create the shapefile, I gave it a path to an existing one. Too bad the zip isn't valid as I can't imagine what it was trying to stuff in there. Thanks for the really detailed screenshot, I will look at the puzzle.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:32:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124875#M333</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T15:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124877#M334</link>
      <description>&lt;P&gt;I've got an an idea for a small code change, modify the code I posted, try changing&lt;/P&gt;&lt;P&gt;for ff in glob.glob(name + ".*"):&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;for ff in glob.glob(name + "*"):&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:43:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124877#M334</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T15:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124878#M335</link>
      <description>&lt;P&gt;OK.&amp;nbsp; Maybe in this I can solve another problem.&amp;nbsp; Can I specify a different folder for shapefile that needs to be zipped and the output zip location?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:38:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124878#M335</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T15:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124883#M336</link>
      <description>&lt;P&gt;I attempted this change to:&amp;nbsp; "for ff in glob.glob(name + "*"):"&lt;/P&gt;&lt;P&gt;and I had the same result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could this be stuffing the zipfile that it is creating into the zipfile that it is creating, creating a loop of sorts?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 15:45:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124883#M336</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T15:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124893#M338</link>
      <description>&lt;P&gt;Improved, skipping the zip to avoid trying to write it into itself:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os
import glob
import zipfile
def zipshape(folder, name):
    os.chdir(folder)
    zipname = name + ".zip"
    flist = glob.glob(name + ".*")
    with zipfile.ZipFile(zipname, "w") as newzip:
        for ff in flist:
            if ff[-4:] != "lock" and ff != zipname: 
                newzip.write(ff)
    return os.path.join(folder, zipname)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 16:49:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124893#M338</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T16:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124923#M339</link>
      <description>&lt;P&gt;This worked perfectly.&amp;nbsp; Thanks so much for helping me with this!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 16:54:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124923#M339</guid>
      <dc:creator>Syvertson</dc:creator>
      <dc:date>2021-12-10T16:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124963#M340</link>
      <description>&lt;P&gt;That's great! Could you mark the first (updated) post with the screenshot of the test model as the solution? I think the post with the ModelBuilder model would be most useful to people looking for an answer to this question.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 18:16:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124963#M340</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T18:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create "Zip" file in Model Builder</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124964#M341</link>
      <description>&lt;P&gt;Good job!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 18:18:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/create-quot-zip-quot-file-in-model-builder/m-p/1124964#M341</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-12-10T18:18:29Z</dc:date>
    </item>
  </channel>
</rss>

