I have a model builder process that will create a shapefile, that later is retrieved by another process. The other process requires a zip file input. Is there any way I can zip up these files within model builder?
Solved! Go to Solution.
The process "calculate values" seems to have created the zip file just fine, but the model builder is stuck on the step. The zip file was created and has not changed file size for about 20 minutes. See screen shot:
I can't understand what would hang it up.
Update to this: 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. See screen shot:
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.
I've got an an idea for a small code change, modify the code I posted, try changing
for ff in glob.glob(name + ".*"):
to
for ff in glob.glob(name + "*"):
OK. Maybe in this I can solve another problem. Can I specify a different folder for shapefile that needs to be zipped and the output zip location?
I attempted this change to: "for ff in glob.glob(name + "*"):"
and I had the same result.
Could this be stuffing the zipfile that it is creating into the zipfile that it is creating, creating a loop of sorts?
Improved, skipping the zip to avoid trying to write it into itself:
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)
This worked perfectly. Thanks so much for helping me with this!
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.
Good job!