Script Library

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.


convert_to_zip.s

Download

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:

test1.csv
test2.csv
test3.csv

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:

test1.zip
test2.zip
test3.zip


  1  WORKINGDIR "C:\PATH\TO\MY\FILES"
  2  :loop
  3  GETNEXTFILE "*.csv"
  4  ;no more file so exit
  5  IFERROR RETURN $ERROR_SUCCESS
  6  SETREPLACE zipname = %nextfile ".csv" ".zip"
  7  ZIP zipname %nextfile /create 
  8  DELETE %nextfile
  9  GOTO loop

Browse complete list of scripts