Peter
Peter

Reputation: 1348

Compress folder in archive named as folder

I want to make a little script to compress folder. In fact I want to do exactly what is done when you right clic on a folder and select "compress": the zip file has the same name as the folder and when you clic on it, it creates back the folder and the files. Here is my code:

set the_src to "Mac Info:Users:Maison:Desktop:Dest_So36"
set the_src to quoted form of POSIX path of the_src

set the_dest to "Mac Info:Users:Maison:Desktop:Dest_So36.zip"
set the_dest to quoted form of POSIX path of the_dest

do shell script "cd " & the_src & ";zip -r " & the_dest & " *"

If I use zip -r it takes all sub folder and file from the orginal folder but when unpacking, it give back the content of the original folder (subfolder and files) but not the main folder itself. It I use zip -jr, it loose all the sub-folder (it get the files but not the folder).

Thanks

Upvotes: 0

Views: 120

Answers (2)

Marc Anthony
Marc Anthony

Reputation: 11

Changing the directory is fine. You don't need the asterisk.

    do shell script "cd '/Users/Maison/Desktop/'; zip -r 'zip-a-dee-doo-dah.zip' 'Dest_So36' "

Upvotes: 1

Michel Kapelle
Michel Kapelle

Reputation: 149

Why are you using cd (changedirectory) to go INTO the folder? When you are in the parent folder, you can use the zip -r command and it will work.

So I believe you command should become:

do shell script "zip -r " & the_dest & ".zip" & the_dest

Upvotes: 0

Related Questions