zip multiple files individually

edited March 2011 in advice
i recently had need to be able to zip a quantity of files individually. enough to warrant finding an automated way of doing it, too ;)

open automator, and create a new custom (blank) worfklow. select the utilities entry in the left-most column, the drag the run shell script action into the blank work area on the right.

set the pass Input pop-up to “as arguments,” and then replace the existing cat code with this text:

for f in "$@" do zip -j "$f.zip" "$f" done

save the script as an application, and then just drag and drop multiple files (not a folder full of files, though), onto the resulting automator app icon.

Comments

  • edited March 2011
    //edit - disregard this comment - this wont happen when using the '-j' flag, as i'd stated above. doh!

    one issue i found with this (tao found it, actually), was that when uncompressing a file, it has a directory hirachy matching that (kind of) of where the files where prior to zipping.

    so, if the files are all at root when you zip them, uncompressing the resulting archive results in the original file.

    if they are on your desktop in a folder, uncompressing the archive will result in something like...
    users  V
    ------
    chris V
    ----------
    desktop V
    ----------------
    folder name V
    ------------------------
    original file.txt
    if anyone knows of a non-cludge workaround, don't hesitate to let us know, innit! ;)
  • edited 7:53AM
    Umm, I'm not having this problem, if I'm understanding it properly. I can drop a file on the app and when it is uncompressed I get just the file in the same location as the ZIP.

    But if you want to look for other flags to use, to see if they help... type:
    zip --h

    And it will give you the available options
  • edited March 2011
    Looking at the man page, it would seem the -j flag should stop the directory shit?

    Edit, yes it does :)
  • edited 7:53AM
    isn't it!

    i dunno why it's happening, really.
  • edited 7:53AM
    I never said... nice tip BTW :)
  • edited 7:53AM
    i know why that was happening - even though i'd told you to use the -j flag, i hadn't actually used it myself. *titter*
Sign In or Register to comment.