Python scripts to zip and unzip data
The topic Input and output data types discusses the use of file data types for input and output parameters in geoprocessing services. A technique you can use for folder-based workspaces (file geodatabase, coverages, and shapefiles) is to use the Zip compression utility to make a .zip file out of a workspace, then use the resultant .zip file as input to the model. Within the model, you can use the unzip script (see below) to unzip the file into a workspace and proceed from there. The same is true for outputs—you can create a .zip file of a workspace and use that for output.
For an example of using the zip script, see GP service example: Clip and ship and GP service example: Data on demand.
You can create your own script tools to zip and unzip using the code described below. You can also check Model and Script tool gallery on the geoprocessing resouce center for tools to zip and unzip data.
- Zip.py takes an input folder and an output file name and creates a compressed .zip file. You should add the .zip suffix to the output file name—the script doesn't automatically add the suffix. The parameter properties are as follows:
Zip.py parametersLabel
Data type
Type
Direction
Input folder
Folder
Required
Input
Output file
File
Required
Output
- Unzip.py takes an input .zip file and an output folder and writes the contents to the folder.
Unzip.py propertiesLabel
Data type
Type
Direction
Input .zip file
File
Required
Input
Output folder
Folder
Required
Input