View Full Version : Script: Make Zip From Dialogs

03-15-2007, 06:25 PM
this code will frist ask the user for the files to add to the archive
then it will ask for the filename and location to save the zip file to
once the file has successfuly been created it will open the folder that it was created in

there is a series of error checking so if there is any error the user is informed

this script is standalone ie: it dosent need any objects on the page to make it work

copy and paste this code into your project or download the lua attached to this post

-- Prompt the user to select files to add to the zip archive.
FilesToAdd = Dialog.FileBrowse(false, "Files to Add", _DesktopFolder, "All Files (*.*)|*.*|", "", "zip", true, false);
-- Check to see if an error occurred, or the user cancelled.
if (FilesToAdd[1] ~= "CANCEL") and (FilesToAdd ~= nil) then
-- set the name and location of the new zip file
SetZipName = Dialog.FileBrowse(false, "Save File As", _DesktopFolder, "All Files (*.zip)|*.zip|", "", "zip", false, false);
-- check that cancel wasent clicked and that a file name was enterd
if (SetZipName[1] ~= "CANCEL") and (SetZipName ~= nil) then
-- Show the status dialog.
-- Add the chosen files to the zip archive.
Zip.Add(SetZipName[1], FilesToAdd, true, "", 5, nil, false);
-- Get the error code of the zip.add action.
error = Application.GetLastError();
-- Hide the status dialog.
-- If it succeeded, display a success message and open the folder. Otherwise display the error message.
if (error == 0) then
Dialog.Message("Success", "The files were successfully archived.", MB_OK, MB_ICONINFORMATION);
-- get the folder where the new zip file was created
FullPath = String.SplitPath(SetZipName[1]);
-- Open the folder where the zip file was created.
File.ExploreFolder(FullPath.Folder, SW_SHOWNORMAL);
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);