create ZIP file Windows

The steps below demonstrate how to create a ZIP file, in Windows 7.

  1. Select the file to be compressed.
  2. Right-click the file and scroll down to Send to, choose Compressed (zipped) folder.

Can that be “hacked” via a shell or otherwise something like (Pseudocode) …

Dim myFolder as Folderitem
myFolder = a particular folder on my hard disk

If myFolder <> Nil and myFolder.exists then
myFolder.CreateZipTheWayWindowsFinderDoesIt
end if

Thanks.

Lennox

Well, you can run zip tool in shell class.
Or use a plugin like our MBS Compression Plugin which has classes to zip files.

Use the Compact command via shell:

http://technet.microsoft.com/en-us/library/bb490884.aspx

There’s an old plugin that is no longer maintained called RealZip which can create and open zip archives. Unfortunately, the ZipFolder functionality of Windows Explorer is not exposed for other applications to use.

Thanks Andrew L,
I will check it out.
Lennox

Thanks Kuzey Atici,
I checked it but I do not know if I can manage that, I will give it a try.
Lennox

Thanks Andrew L,
I downloaded it but I cannot get it to work, may be because I do not know how to use plugins.
I added the plugin to the Plugins folder in the Real Studio folder.
Lennox

There should be a demo project with the plugin.

There’s also my x-platform “TT’s Zip Package” to create and read zip files: http://www.tempel.org/RB/ZipPackage

[quote=26153:@Kuzey Atici]Use the Compact command via shell:

http://technet.microsoft.com/en-us/library/bb490884.aspx[/quote]

Can someone provide an example of this or modify the code below?

Dim myFoldertoCompress as folderitem
myFoldertoCompress = Specialfolder.Desktop.Child(“my Folder to Compress”)

  Dim sh As Shell      
  sh = new Shell
 sh.execute [{/c|}] [/s[:myFoldertoCompress]] [/a] [/i] [/f] [/q] [FileName[myFoldertoCompress.name + ".zip"]]

Thanks.

Lennox

See the examples on that page at the bottom

MBS Compression Plugin can also read and write zip archives.

Thanks Norman,

I have seen them but still cannot get it going … lack of knowledge/expertise on my part.

Lennox

@Lennox: then you’d better tell us EXACTLY what the problem is. What did you do in step 1, step 2 and so on? What was the result? And what would you have expected? Zip ain’t really rocket science.

Thanks for your offer to assist Beatrix,

I have a folder… myFoldertoCompress = Specialfolder.Desktop.Child(“my Folder to Compress”)
myFoldertoCompress already exists on the desktop and contains 85 files, no folders

I would like to create a .zip archive of that folder, so my code is…

  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
  myFoldertoCompressZipped = SpecialFolder.Desktop.Child("my Folder to Compress.zip")    // This is the .zip file I want to create
  
  Dim sh As Shell
  sh = new Shell
  sh.execute compact /c /myFoldertoCompress *.*

On compiling my app I get this error…

This item does not exist
sh.execute compact /c /myFoldertoCompress . // compact is highlighted

sh.execute /c /myFoldertoCompress .
On compiling my app I get this error…

There is more than one item with this name and it’s not clear to which this refers.
sh.execute /c /myFoldertoCompress . // sh.execute is highlighted

sh.execute c /myFoldertoCompress .
On compiling my app I get this error…

This item does not exist
sh.execute c /myFoldertoCompress . // c is highlighted

What can I do?

Thanks again.

Lennox

Hi Lennox,

at the very least you need to add quotes around the shell command:

sh.execute "compact /c /myFoldertoCompress *.*"

OK Beatrix Thanks,

It compiled now, this is my new code…

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
myFoldertoCompressZipped = SpecialFolder.Desktop.Child(“my Folder to Compress.zip”) // This is the .zip file I want to create

Dim sh As Shell
sh = new Shell
'sh.execute /c /myFoldertoCompress .
sh.execute “compact /c /myFoldertoCompress .

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

and when I ran it I got this msgbox
https://www.mediafire.com/?dqqvc1lk4j8thvc

Any other suggestions?

Thanks again.

Lennox

Hi Beatrix,

I added shell path, this is my new code…

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
end if
myFoldertoCompressZipped = SpecialFolder.Desktop.Child(“my Folder to Compress.zip”) // This is the .zip file I want to create

Dim sh As Shell
sh = new Shell
'sh.execute /c /myFoldertoCompress .
sh.execute “compact /c /myFoldertoCompressShellpath .

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

same error.

Any other suggestions?

Thanks.

Lennox

myFolderToCompressShellPath doesn’t need the / . And it needs to be outside of the quote. The latest part . isn’t necessary - I think. Try with:

sh.execute "compact /c + " myFoldertoCompressShellpath"

You may need the /s and not the /c on second reading of the error message. This one says directory.