Sample scripts are provided as-is with no warranty of fitness for a particular purpose. These scripts are solely intended to demonstrate techniques for accomplishing common tasks. Additional script logic and error-handling may need to be added to achieve the desired results in your specific environment.
Wildcards are supported with the ZIP script command, but this does not always produce the desired effect.
For example, let's say that you have a directory with the following three files:
The following command will produce a single zip archive named "zipped_files.zip" that contains all three of the above files:
ZIP "zipped_files" "*" /create
If your goal is to produce a separate zip archive for each of the files listed above, then using a wildcard as above will not work.
In cases like this you need to use the GETNEXTFILE command to identify the file(s) and then pass the file name in a variable to the ZIP command. Doing this inside of a loop will enable GETNEXTFILE to find all of the files that match a given wildcard pattern.
This sample script demonstrates this technique by iterating over a directory of .csv files and converting each one into a zip file with the same base name as the original file.
If you start off with the list of files above, this sample script will produce the following files:
1 WORKINGDIR "C:\PATH\TO\MY\FILES" 2 :loop 3 GETNEXTFILE "*.csv" 4 IFERROR= $ERROR_NO_FILE_FOUND goto no_more_files 5 SET source = %nextfile 6 ;; The following command splits off the .csv extension 7 ;; and assigns the base part of the filename to the variable "target" 8 SETRIGHT target = source 4 /split 9 ;; If the original file is "test1.csv" then you will end up with 10 ;; a file named "test1.zip" 11 ZIP target source /create 12 DELETE source 13 GOTO loop 14 :no_more_files 15 ;; Done processing