Hello
I have hundreds of folders to zip and I’m creating a script. Many folders have spaces and this creates problems.
I know that the command for zip a folder can be: zip -r -X archive_name.zip folder_to_compress
But I need to convert this command to something that accept space in path and in name of zip
So, a folder Apex (OpenType) have to become Apex (OpenType).zip
Can someone help me to write a valid command that maintain space?
Thank you in advance
The thing that will help is to quote the variable used so that the shell doesn’t view those spaces (or other characters) as separators. But, don’t try to do it yourself by just adding quote characters. Instead use the AppleScript “quoted form of” command.
If you had the folder name/path in a variable someFolder, you’d do this:
set someZip to someFolder & ".zip"
do shell script "zip -r -X " & quoted form of someZip & " " & quoted form of someFolder
Note that, in my example, I’m assuming that someFolder doesn’t include the colon at the end (if it is the path of the folder). If your variable does, you’d obviously need to remove that before adding “.zip” at the end.
Thank you Krioni for answer
I have a script that try to get the element(s) by drag&drop with
on open these_items
try
repeat with this_item in these_items
tell application "Finder" to set this_item_name to name of this_item
listing(this_item, this_item_name)
end repeat
Ending()
end try
end open
So si right to translate your script in these way?
set this_item to someFolder & ".zip"
do shell script "zip -r -X " & quoted form of this_item & " " & quoted form of someFolder
That’s true but I guess I’m driven to putting the ‘as text’ there so I can alternatively make an HFS reference. Without the posix path of, it will generate a list.