create ZIP file Windows

Besides being the easiest to use, it can also unzip a password-protected zip file and that put the Compression plugin above all the other solutions I looked at.

Hi Beatrix,

I removed 78 of the files so I have seven now.
This seems to be the best but I do not get the zip file… it is not created

Dim myFoldertoCompress, myFoldertoCompressZipped as folderitem
myFoldertoCompress = Specialfolder.Desktop.Child(“my Folder to Compress”) // This folder already exists on the desktop and contains 85 files, no folders
If myFoldertoCompress.exists then
Dim myFoldertoCompressShellpath as string
myFoldertoCompressShellpath = myFoldertoCompress.Shellpath
'msgbox myFoldertoCompressShellpath
end if
myFoldertoCompressZipped = SpecialFolder.Desktop.Child(“my Folder to”) // This is the .zip file I want to create
// "“C:\Documents and Settings” + app.gUsername + “\Desktop”
Dim sh As Shell
sh = new Shell
'sh.execute “compact /c /s” + myFoldertoCompress.Shellpath ’ Capture 4 // + " " + “.” + “/a/i/f/q/” + myFoldertoCompressZipped.Shellpath
sh.execute “compact /s” + myFoldertoCompress.Shellpath 'Capture 5 // + " " + “.” + “/a/i/f/q/” + myFoldertoCompressZipped.Shellpath

If sh.errorCode = 0 then
MsgBox "No Error - " + Str(sh.errorCode) + " : " + sh.Result
MsgBox "Error " + Str(sh.errorCode) + " : " + sh.Result
end if

This is the msgbox …

How can I create the zip file now?



[quote=214849:@Lennox Jacob]I removed 78 of the files so I have seven now.
This seems to be the best but I do not get the zip file… it is not created[/quote]

Before creating your shell code, have you simply tried in the Command Prompt accessory manually to see if it worked ?

Hi Michel,

I don’t know what is “the Command Prompt accessory”.

I tried “Right-Click” on “my Folder to Compress.”, /Send to/Compressed(zipped) folder and that creates a genuine zip archive with all the files.



The Command Prompt accessory is the equivalent of the Linux or Mac OS X terminal. That is where you type command lines such as the one you are trying to use in your program.

You find it in All apps, Windows System, Command Prompt.

It typically works like a terminal : you type the command, hit enter, and the computer executes the command.

The main interest of such a program is that you can immediately see what the result is without having to run a Xojo program. Then when you have verified it works, you can use the same command in a shell.

The fact that you have no zip file created seems to indicate some flaw either in your Xojo code, or in the shell command. With the command prompt terminal, you can verify it actually works before looking elsewhere.

Thanks Michel, for a great explanation, I did not know that, I only knew it for Mac.
I will try it and see what happens.
Thanks again.

Lennox, you first need to figure out the command for compressing your files, as Michel suggested, and then recreate that command string and pass that to sh.execute. I hope that’s clear by now.

One error I see in your code:

sh.execute "compact /s" + myFoldertoCompress.Shellpath

That resolves to the command string, for example:

compact /sC:\Users

See the issue there? A missing space before the path!

“/s” is an option, like those “-…” options you pass to unix / OS X commands. Windows uses “/” for options.

And if you keep having trouble, I suggest you download my Zip package - you don’t have to purchase a license if you only use the original code, not the ZipFolderItem class. The demo project contains an example for zipping a folder like you want to.

The compact command line tool has nothing whatsoever to do with zip archives. It displays or alters the filesystem-level compression of files on NTFS partitions.

Thanks for clarifying that. I had been wondering about that command name and wanted to ask but forgot. One more reason to try my zip classes :slight_smile:

Thanks Thomas for the offer and Andrew for letting me put this venture to rest, thanks also to Beatrix and Michel for their input.