dim dlg as new OpenDialog
dlg.InitialDirectory = SpecialFolder.Desktop
dim f as FolderItem = dlg.ShowModalWithin(self)
if f <> nil then
dim h as FolderItem = SpecialFolder.Desktop.Child("myZip")
// if h = nil and not h.Exists then
//h.CreateAsFolder
//end if
dim s as new Shell
s.Execute "zip " + h.ShellPath + " " + f.ShellPath
end if
The file gets zipped all right, but when I unzip it by double-click I find it nested in two folders:
Users, containing the following folder
CarloRubini, containing the actual file
Is there a way to zip the file in such a way that the two folders get skipped?
My guess from that is that you need to cd into the folder above “f” before creating the zip file. When yo upass h.ShellPath, you’re passing the complete path, so:
/Users/CarloRubini/TheStuffYouWanted
Therefore, you need to cd into /Users/CarloRubini/ and then execute the ZIP command:
I have a similar problem. In my program I create a temporary folder with all files/folders generated by my program. Let’s say the folder is stored in SpecialFolder.Desktop.
I want to let my users know where the zip file is created. I would like to offer him an OpenDialog where he can select the file path and its name. Now, unnoticed by the user, a zip file should be output from the temporary folder exactly at this point. After this has happened successfully (you can check this via the shell object), the temporary folder should be deleted on the desktop.
The above shell call to create zip files should also work on Linux, right? Is there a Windows counterpart?
Previously, Apple’s website gave a detailed description of the ZIP command, this page has not existed for a long time and one can only hope that the shell command is not deprecated!
Hi Tim,
it works all right. Yet only if the name of the file selected to be zipped does not contain any space.
I unsuccesfuly tried encodeUrlComponent.
Any idea?
I’ve created a small sample project. It creates the temporary folder which should be zipped on a user selected place. But it did not create a zip file.
Here is a shell that, at present, works, ignoring the parent folders. It seems that -j does the trick:
s.Execute "zip -j " etc.
As for the output name, I noticed that I have to leave out the extension part of the fileName; or add .zip to f.displayName
dim dlg as new OpenDialog
dlg.InitialDirectory = SpecialFolder.Desktop
dim f as FolderItem = dlg.ShowModalWithin(self)
if f <> nil then
dim r() as String = f.DisplayNameSplit(".")
dim h as FolderItem = SpecialFolder.Desktop.Child(r(0))//or f.displayName + ".zip"
dim s as new Shell
s.Execute "zip -j " + h.ShellPath + " " + f.ShellPath
end if
If the name of the zip archive does not contain an extension, the extension .zip is added. If the
name already contains an extension other than .zip, the existing extension is kept unchanged. How-
ever, split archives (archives split over multiple files) require the .zip extension on the last
split.
[code]Dim input As FolderItem = TempFolder
Dim output As FolderItem = SpecialFolder.Picture.Child(output.zip)
Dim s As String
s = cd + input.ShellPath + ; +_
zip -r + output.ShellPath + + input.ShellPath + *
Shell1.Execute(s)[/code]
This now packs my temporary folder including all files/folders into a user selected file path. But it stores a third folder in it Users/…. Please test it. I dont want the third folder. Can someone help please?
@Tim Jones thats totally weird. Using your String do also include the Users/… folders on my Mac. I modified the string to
s = "cd """ + input.ShellPath + """ ; " +_
"zip -r """ + output.ShellPath + """" + " " + """ + input.ShellPath + "" *"
Now it only writes to files I wanted, but if the output filename contains whitespaces, ill get for example Ohne\ Titel.zip instead of Ohne Titel.zip. Why?