PDA

View Full Version : Zip.Extract to recreate folder structure?


llabate
09-25-2008, 05:16 PM
I have read other posts regarding this, but I haven't been able to find a way around this problem. I want to use Zip.Extract to extract and recreate the subfolders just as they were in the folder that they were backed up from (i.e. for potential rollback after an upgrade). I am using the following code to zip up the files noted below it:

ZipBackupFile = "C:\\ZipFolderTest";
BackupFolder = "C:\\topfolder";
tblFilesToBackup = {};
tblFilesToBackup = File.Find(BackupFolder,"*.*",true,true,nil);
Zip.Add(ZipBackupFile,tblFilesToBackup,true,"",true,0,nil,true);

then later:
Zip.Extract("C:\\ZipFolderTest.zip",{"*.*"},"C:\\extractfolder",true,true,"",ZIP_OVERWRITE_ALWAYS,nil);

files to be zipped:
c:\topfolder\subfolder1\test1.txt
c:\topfolder\subfolder1\test2.txt
c:\topfolder\subfolder2\test3.txt
c:\topfolder\subfolder2\test4.txt

desired extraction structure:
c:\extractfolder\subfolder1\test1.txt
c:\extractfolder\subfolder1\test2.txt
c:\extractfolder\subfolder2\test3.txt
c:\extractfolder\subfolder2\test4.txt

What I actually get with Zip.Extract (depending on how "include folders" and "recurse" are set) is either:

c:\extractfolder\test1.txt
c:\extractfolder\test2.txt
c:\extractfolder\test3.txt
c:\extractfolder\test4.txt

- or - the above plus the two empy folders, subfolder1 and subfolder2. I can't seem to extract the files ~into~ the subfolders.

Help! Thanks in advance for any suggestions.

Ulrich
09-25-2008, 07:32 PM
Here is an example to compress a folder:

-- define source folder to compress
FolderName = Dialog.FolderBrowse("Select the folder to compress", _TempFolder)
-- define destination archive
ZipBackupFile = _TempFolder .. "\\IR_ZipActions.zip";
-- include everything in the source folder
tblFilesToBackup = { FolderName .. "\\*.*"}
-- perform the file compression (without callback, so wait for confirmation/error dialog)
Zip.Add(ZipBackupFile, tblFilesToBackup, true, "", 5, 0, true);
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Dialog.Message("Success", "Folder " .. FolderName .. " was successfully compressed to " .. _TempFolder .. "\\IR_ZipActions.zip\r\n" .."Please examine the file (with WinZip or something else) before proceeding." , MB_OK, MB_ICONINFORMATION);
end


And here I decompress it:

-- try to uncompress the file IR_ZipActions.zip in your temporary folder
if (File.Find(_TempFolder, "IR_ZipActions.zip") == nil) then
Dialog.Message("Error", "The expected zip file was not found.\r\nDid you compress any folder first?", MB_OK, MB_ICONEXCLAMATION);
else
-- perform the uncompression (again withou callback, so wait for outcome)
Zip.Extract(_TempFolder .. "\\IR_ZipActions.zip", {"*.*"}, _TempFolder .. "\\Extractfolder", true, true, "", ZIP_OVERWRITE_ALWAYS);
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Dialog.Message("Success", "The files contained in " .. _TempFolder .. "\\IR_ZipActions.zip were recursively extracted to " .. _TempFolder .. "\\ExtractFolder\\\r\nCheck the folder contents now.", MB_OK, MB_ICONINFORMATION);
end
end


Ulrich

llabate
10-02-2008, 11:00 PM
Thanks so much, Ulrich. In the end they decided to go with another backup method, but I will save this code for future reference, as I know it will come up again :)

kk250040
12-10-2008, 04:57 AM
Are Zip.Add and Zip.Extract part of Setup factory?? I am using SF7 version.
I am getting errors saying :

attempt to index global 'Zip' (a nill value)

I did not find any help information in the help stuff too, does that mean that the command itslef is not available in SF7?

Can anyone comment on this with any useful information to zip and extract files from SF, or if I have any command line commands for windows to zip files?

Ulrich
12-10-2008, 06:33 AM
Are Zip.Add and Zip.Extract part of Setup factory?? I am using SF7 version.

Yes, it is. But maybe you haven't enabled it in your setup. Check in the menu of SUF70, under Resources > Plugins, and see if the Zip option is checked.

Ulrich

kk250040
12-10-2008, 11:14 AM
:yes Working now,
My Zip plugin was unchecked as you said
ThankYou!

kk250040
12-11-2008, 07:25 AM
This is all okay, but I still do not have the Zip.Add or related stuff in the HelpFiles. Can someone post the syntax and its support details from their respective help files if they have it. I am trying to get a Progress bar while zipping my contents for backup and I dont have the help file for the Zip.Add to refer. The samples might work, but I want to know in and out of the command before I use it in my setups.

Please paste it here, or guide me where I can get it, or why I do not have it in the referring manuals?


ThankYou!

Ulrich
12-11-2008, 08:27 AM
This is all okay, but I still do not have the Zip.Add or related stuff in the HelpFiles. Can someone post the syntax and its support details from their respective help files if they have it.

Hello,

plugins are extensions to the product, and their help files are separate from the product's own docs, provided by the writer of the plugin - not necessarily Indigo Rose.

For most available plugins, you can see the shipped help file this way:
In the menu, go to Resources > Plugins, select the plugin, click About Plugin, then click Plugin Help. This should open the documentation, which can be a HTML file, PDF doc, etc.

Ulrich

kk250040
12-11-2008, 08:57 AM
:yes Thank You Ulrich