Zip Command Help!

Discussion in 'Mac Programming' started by flashuni, Jun 8, 2008.

  1. flashuni macrumors newbie

    Joined:
    Jun 7, 2008
    #1
    I am trying to preserve the resource forks in font files while zipping them.
    The font files are in folders, and I am trying to zip each folder up individually and not just into one big archive.

    What is the zip parameter to do this?
     
  2. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #2
    Give this a try.

    Code:
    ls -d /path/to/your/parent/dir | sed 's/^/"/;s/$/"/' | xargs -I {} -n1 zip -r {}.zip {}
    -numero
     
  3. flashuni thread starter macrumors newbie

    Joined:
    Jun 7, 2008
    #3
    Thanks

    Thanks a bunch, but your script makes my fonts folder into one big archive.

    Is their any way that I could do this piece of code to each folder inside on my fonts folder. When I ran it, it just created a large archive of my whole fonts folder and didn't just zip up each folder individually inside of the fonts folder.

    Thanks, Flashuni

    For Example Here is my previous script that doesnt work:
    ## zip the contents of each folder in the current directory into an archive:
    for d in *; do if [ -d "$d" ]; then cd "$d"; cd ..; fi; done

    ## zip every folder in the current directory into an archive:
    for d in *; do if [ -d "$d" ]; then zip -r -j "$d.zip" "$d"; fi; done

    ## example recursively forces the deletion of the directory if zip returns true:
    for d in *; do
    if [ ! -d "$d" ]; then
    continue
    fi
    if ! zip -R -j "$d.zip" "$d"; then
    continue
    fi
     
  4. motulist macrumors 68040

    motulist

    Joined:
    Dec 2, 2003
  5. flashuni thread starter macrumors newbie

    Joined:
    Jun 7, 2008
    #5
    I have tried that, but if someone could point me in the right direction it would be a great help!

    Thanks, Flashuni
     
  6. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #6
    To fix the problem with your fonts dir being zipped do this

    Code:
    ls -d /path/to/your/parent/dir/* | sed 's/^/"/;s/$/"/' | xargs -I {} -n1 zip -r {}.zip {}
    I added the "/*" to the parent dir path.

    What you want fed into the sed command is the list of directories that will be zipped. Do just the "ls -d /path/to/parent/dir/*" command by hand and see if that gives you the folders that you want individually zipped.

    Sorry about that little slip. You are just feeding something in that is one level too high. It should work with this change.

    -numero
     

Share This Page