-- Written by NoiseCrime Feb 27 2000
-- This code may be freely distributed, but must include the above
--acknowledgement. thanks
-- HELP:
-- To zip a file use
-- ZIPaFile (Name_Of_Zipped_File, ZIPcompression, fileorfolder)
-- Name_Of_Zipped_File = The final name you want to call the zipped file,
-- e.g. "backup.zip"
-- ZIPcompression = You can decide to compress the zip file or not
-- 0 = no compression, 1 = compression
-- FileorFolder = You can elect to zip a single file, or the entire folder
-- NOTE: If you are selecting to Zip a folder,
-- you must 'open' a file from within that folder.
-- This is the only way using these xtras to achieve this.
-- Maybe BuddyAPI has a select dialogue box, need to check.
-- COMMENTS:
-- From testing on a Mac,
--i discovered that saving as a zip, using ZipFile, doesn't compress,
-- however using Jarfile does, and quite effectively too.
-- You could write your own 'select/open' routine so you could select
specific -- files from a folder and add them to the file list
-- It would also allow for a happier method of selecting a folder.
-- Testing has been done on mac using D8 beta
-- the zip file is placed in the same folder as the files to be zipped.
-- XTRA'S REQUIRED:
-- File I/O
-- Used for the open dialogue box - is there a better way to select a folder?
-- FileXtra -- Used for creating a file list of a selected folder
-- This can be found in the 'JaveAsJava' folder in the D7 xtra folder
-- I imagine its still in the D8 'SaveAsJava', but that wasn't in my beta
-- If you've not used it before, the definately check it out.
-- ZipXtra
-- Can zip, cab, and Jar files
--
-- Comes with D8 only, found in the 'Media Support' folder, in the xtras
folder
on ZIPaFile Name_Of_Zipped_File, ZIPcompression, FileorFolder
-- Use Basic FileIO to select a file
ZipFileName = FILEIO_SelectaFile()
if ZipFileName = "" then
alert ("No File selected to zip")
exit
end if
-- GRAB THE DIRECTORY NAME of where the files are to be Zipped from
ZipDirectory = FILE_getFolder (ZipFileName)
-- GET FILE LIST TO ZIP. EITHER SINGLE FILE OR FOLDER CONTENTS
case FileorFolder of
#file: filelist = [ FILE_getfile (ZipFileName) ] -- ZIP FILE
#folder: filelist = DirectoryToList(ZipDirectory) -- this is a call to
the filextra (no need for creating an object though)
otherwise
ALERT ("Error: FileorFolder Not valid must be 0 or 1")
exit
end case
-- CREATE A ZIP OBJECT
ZIPobject = VOID
ZIPobject = new (xtra "ZipXtra")
if ZIPcompression = 0 then
ZipFiles (ZIPobject, ZipDirectory, Name_Of_Zipped_File & ".zip",
filelist)
-- No compression
else
JarFiles (ZIPobject, ZipDirectory, Name_Of_Zipped_File & ".zip",
filelist) -- Compression
end if
end
on FILEIO_SelectaFile
-- CREATED A NEW INSTANCE OF FILE I/O OBJECT
FileIOobject = VOID
FileIOobject = new(xtra "fileio")
-- ALLOWS USER TO OPEN A FILE. THIS WILL GIVE US THE DIRECTORY FOLDER
nFileName = displayOpen(FileIOobject)
FileIOobject = VOID
return (nFileName)
end
on FILE_getFolder nFilename
-- STRIPS OUT THE FILENAME TO LEAVE JUST THE DIRECTORY STRUCTURE
-- ALSO ADDS A FINAL "/" or ":" AS THE ZIPDIRECTORY MUST END IN ONE OF --THESE
oldD = the itemdelimiter
if the platform contains "Windows" then
the itemdelimiter = "/"
else
the itemdelimiter = ":"
end if
lastitem = the number of items in nFilename
delete item lastitem of nFilename
nFilename = nFilename & the itemdelimiter
the itemdelimiter = oldD
return (nFilename)
end
on FILE_getFile nFilename
-- SIMPLY RETURNS THE FILE NAME
-- FOR USE WHEN ZIPPING A SINGLE FILE
oldD = the itemdelimiter
if the platform contains "Windows" then
the itemdelimiter = "/"
else
the itemdelimiter = ":"
end if
lastitem = the number of items in nFilename
nFilename = ITEM lastitem OF nFilename
the itemdelimiter = oldD
return (nFilename)
end