zip options archive inpath inpath ...
where archive is a new or existing zip archive and inpath is a directory or file path optionally
including wildcards. When given the name of an existing zip archive, zip will replace identically
named entries in the zip archive (matching the relative names as stored in the archive) or add
entries for new names. For example, if foo.zip exists and contains foo/file1 and foo/file2, and the
directory foo contains the files foo/file1 and foo/file3, then:
zip -r foo.zip foo
or more concisely
zip -r foo foo
How can I implement that on Mac…
The folder I want to “zip” is special folder.Desktop.child("The unzipped docs)
There are issues when using the command line Zip function, namely it includes the full path in the compressed file. I’d suggest checking into TT’s Zip as Kem mentioned.
This is not my experience. It uses the standard unix convention of taking the input literally. To make a relative directory tree you just need to compress from one level above.
/Users/Eduo$ zip -r files /Users/Eduo/Desktop/Files/*
Final zip file contains /Users/Eduo/Desktop/Files/*
/Users/Eduo$ zip -r files Desktop/Files/*
Final zip file contains Desktop/Files/*
So the trick is to first move to the directory above the one you want to compress, and then zip that. If you pass the full path from elsewhere you compress the full path (but just the contents you intend).
[quote=21212:@George Balla]If you use any of the shell functions in OS/X will your application get accepted if you
submit to the app store??[/quote]
You’d likely need to use some sort of Entitlement to allow access to the specific function you need, and you’d need to justify using the shell to access that function instead of some other API.
[quote=21226:@Thomas Erwin]You’d likely need to use some sort of Entitlement to allow access to the specific function you need, and you’d need to justify using the shell to access that function instead of some other API.
someSource [mixed] file or folder, list of files or folders. Must be an alias, file, or HFS path or a list of these classes
destinationFolder [mixed] destination folder. Must be an alias, file, or HFS path. Leaving it empty ("" or missing value) saves the archive in the directory of the source
erase [bool] if true, erase files/folders after creating the archive
keepParent [bool] if true, keep original name of parent folder while creating an archive of a folder
result: the alias of the created archive or boolean false, if an error occured
)
on ZipIt from someSource given erase:erase, keepParent:keepParent, destinationFolder:dFolder
if class of someSource is list then
set tempFolder to quoted form of (POSIX path of (path to temporary items) & “zip_temp_folder”)
try
do shell script "mkdir " & tempFolder
on error
try
do shell script "rm -r " & tempFolder & "/"
end try
end try
repeat with i in someSource
set s to POSIX path of (i as alias)
if s ends with “/” then set s to text 1 thru -2 of s
do shell script "cp -pr " & quoted form of s & space & tempFolder
end repeat
set {name:Nm} to info for item 1 of someSource as alias
set source to POSIX path of (item 1 of someSource as alias)
try
set destination to POSIX path of (dFolder as alias) & “Archive.zip”
on error
set destination to text 1 thru ((offset of Nm in source) - 1) of source & “Archive.zip”
end try
try
do shell script "/usr/bin/ditto -c -k -rsrc " & tempFolder & space & quoted form of destination
if erase then
repeat with i in someSource
do shell script "rm -r " & quoted form of POSIX path of (i as alias)
end repeat
end if
try
do shell script "rm -r " & tempFolder
end try
return POSIX file destination as alias
on error
return false
end try
else
set k to space
if keepParent then set k to " --keepParent "
set {name:Nm, name extension:Ex, folder:Fo, package folder:Pa} to info for someSource as alias
set source to POSIX path of (someSource as alias)
if Fo and Pa is false then
try
set destination to text 1 thru -2 of (POSIX path of (dFolder as alias)) & “.zip”
on error
set destination to text 1 thru -2 of source & “.zip”
end try
else
if Ex is missing value then set Ex to “”
if Ex is not “” then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
try
set destination to POSIX path of (dFolder as alias) & Nm & “.zip”
on error
set destination to text 1 thru ((offset of Nm in source) - 1) of source & Nm & “.zip”
end try
end if
try
do shell script “/usr/bin/ditto -c -k -rsrc” & k & quoted form of source & space & quoted form of destination
if erase then do shell script "rm -r " & quoted form of source
return POSIX file destination as alias
on error
return false
end try
end if
end ZipIt
– Examples
ZipIt from (choose file with multiple selections allowed) without erase and keepParent given destinationFolder:path to desktop
ZipIt from (choose folder) with keepParent without erase given destinationFolder:""
tell application “Finder”
set s to files of (path to pictures folder) whose name extension is “jpg”
end tell
ZipIt from s without keepParent and erase given destinationFolder:choose folder
If sh.errorCode = 0 then
theResult = sh.result
else
MsgBox "Error " + Str(sh.errorCode) + " : " + sh.Result
end if
Best regards.
François
*********** end quote************
… and that works for me.
Thanks again.
Lennox[/quote]
yes that works fine, but how to unzip?
Crash on sh.execute cmd
I use in DropDown
[code]
/// unzip
if right (item.name,3)=“zip” then
Dim sh As Shell
Dim cmd as String
dim dlg as New SelectFolderDialog
dim f as FolderItem
dlg.ActionButtonCaption = “Select”
dlg.Title = “Data Folder”
dlg.PromptText = “Select Folder”
f = dlg.ShowModalWithin(Window1)
cmd = "unzip -a " + item.ShellPath + " -d " + f.ShellPath
if f <> nil then
sh.execute cmd /// crash here!!
else
return
end
else
///// zip
dim source, destination as FolderItem
Dim cmd, qPosixOriginalFolder, qPosixBackupFile, theResult As String
Dim sh As Shell
source=Item
dim dlg as SaveAsDialog
dlg=new SaveAsDialog
dlg.Filter=FileTypes1.ApplicationZip
dlg.SuggestedFileName=item.Name
destination=dlg.ShowModalWithin(Window1)
if destination<>nil then
qPosixOriginalFolder = source.ShellPath
qPosixBackupFile = destination.ShellPath
cmd = "/usr/bin/ditto -c -k -X --rsrc "+ qPosixOriginalFolder + " " + qPosixBackupFile
sh = new Shell
sh.execute cmd
If sh.errorCode = 0 then
theResult = sh.result
return
else
MsgBox "Error " + Str(sh.errorCode) + " : " + sh.Result
return
end if
else
return
end
I created a temporary Folder “MyFolder” with Files and Subfolders inside:
[code]MyFolder
ABC.txt
Other Folder
++ new.txt[/code]
I only want to store the Files and Folders inside of MyFolder into Zip. How will the right OS X Shell-Command looks like?
Dim savePath As String = GetFolderItem("Test.zip").ShellPath saves a huge Folderstructure inside…