Creating a zip file and recursing through subfolders

To answer your questions:

  1. It does it one at a time. Based on the request, he wanted to compress a single folder into an archive. The bash script doesn’t handle this, the for-loop does within KM

  2. The syntax for compressing multiple files with zip is zip file.zip file1 file2 file3

Here’s a little more context into what’s happening with the script:

SAVE_DIR=`dirname "$KMVAR_Path"`

Gets the directory name for the Path. If the path is /Users/myname/Desktop/My Folder then the dirname is /Users/myname/Desktop

BASE=`basename "$KMVAR_Path"`

This gets the name of the folder without the dirname. From the example above, we’d get “My Folder”

BASE_NO_EXT=${BASE%.*}

This isn’t necessary unless you’ve selected a file with an extension. This will strip off the “.txt” from a file name like “file.txt”

pushd "$SAVE_DIR"

push the save path into the directory stack

zip -rm "$BASE_NO_EXT" "$BASE"

zip up the folder

popd

pop the last path added to the directory stack. In our case here, it’s “$SAVE_DIR”


For compressing all of the selected files into a single archive, that’d take a bit more work. If someone’s looking for this particular solution, I’ll write it up, otherwise I’ll save myself some work :slight_smile: