how to create individual archives?

How do I make the script below compress each item as an individual archive?
Currently all items dropped to it are combined into one archive. I need each folder to be its own archive named with .zip added to the original folder name.

Any help is appreciated.

John


on open fileList
	if fileList is {} then
		display dialog "Drop files onto this application to zip them." buttons {"OK"}
	else
		-- the following code is just to figure out
		-- what the name of the zip archive should be
		
		
		copy name of (info for (item 1 of fileList)) to fileName
		set fileName to (fileName)
		
		copy (fileName & ".zip") to zipFileName
		copy item 1 of fileList to firstFile
		
		tell application "Finder"
			set zipFolder to ((container of firstFile) as alias)
		end tell
		
		-- this is the part that actually adds the files and zips them
		tell application "ZipIt"
			activate
			set the_window to (make new window at beginning)
			repeat with file_to_zip in fileList
				add file_to_zip to the_window
			end repeat
			compress the_window name zipFileName in zipFolder
			quit
		end tell
	end if
end open

AppleScript: 1.9.3
Browser: Firefox 1.5.0.6
Operating System: Mac OS X (10.3.9)

Hi John:

I don’t think I understand exactly what you want. Do you desire that each individual file (of a group of files dropped onto your droplet) is processed and saved individually as a separate zip file? What you currently have looks like it takes the container of the first file, sets it as the place to store all the zipped files, then tells ZipIt to fill its window with every file in the list, and zip them all en masse to a single file, named for the first file in the dropped list.

If you want each file zipped separately, this modification MIGHT work, but I do not have a copy of ZipIt to test it out:


on open fileList
	if fileList is {} then
		display dialog "Drop files onto this application to zip them." buttons {"OK"}
	else
		-- the following code is just to figure out
		-- what the name of the zip archive should be
						
		tell application "Finder"
			set zipFolder to ((container of (item 1 of fileList)) as alias)
		end tell
		
		-- this is the part that actually adds the files and zips them
		tell application "ZipIt"
			activate
			set the_window to (make new window at beginning)
			repeat with file_to_zip in fileList
				set zipFileName to ((info for file_to_zip)'s name & ".zip")
				add file_to_zip to the_window
compress the_window name zipFileName in zipFolder
			end repeat
			quit
		end tell
	end if
end open

Good Luck, hope this helps.

Hi

i know you guys have this one sorted.
Just wanted to say i use this to zip files.

tell application "Finder"
	activate
	set x to choose folder --pick the folder to work on
	set theitem to every file of folder x
	repeat with theitem in theitem -- go through each item in the folder
		select theitem
		---------------------------------------------------------------------------------------------------
		tell application "System Events"
			tell process "Finder" to click menu item 21 of menu "File" of menu bar 1
			display dialog "Archiving.. Please Wait." giving up after 1
		end tell
		---------------------------------------------------------------------------------------------------
		-- this bit above creates the archive
	end repeat
end tell
tell application "Finder" to move (every file in the folder x whose name does not end with ".zip") to the trash

To All - Thanks a bunch.
Jacques - Yours is dead on to what I wanted to do!

This is working great. I’ve changed it a bit to what you see below.

Now, I want to try and get zipit to verify each archive before closing.
It has this in its dictionary but I can’t seem to get it to do it.
I thought by simply putting “verify” before close would do the trick but it comes back with the error of “Some data was the wrong type” in the script editor with edit or ok as my options.

This is what the dictionary shows for “verify”
verify: Verifies files in the archive.
verify a list of reference – References to the entries to verify. Defaults to selected entries in the frontmost window.
[segments a list of file specification] – List of segments in the archive
Result: boolean – True if everything was verified without any errors.

Again, help from those that really know what they are doing is appreciated.
John


on open fileList
	tell application "Finder" to set zipFolder to (container of (item 1 of fileList)) as alias
	tell application "ZipIt"
		launch
		repeat with i in fileList --repeat for each item
			set zipFileName to name of (info for i) & ".zip"
			tell (make new window)
				add i -- this is what does each item
				compress name zipFileName in zipFolder
				close
			end tell
		end repeat
		quit
		tell application "Finder"
			delete (items in fileList)
		end tell
	end tell
end open

Jacques, Thanks again!!

Now here is another question . . .

I have a dropbox made with Stuffit Express PE, part of Stuffit Deluxe.

It does the same thing zipit does as far as turning groups of individual folders dropped at one time into a single archive.

I want it to do what has been done here, drop a group of folders at once and turn each folder into its own archive.
Unlike dropstuff the drop box does not offer the preference of individual archives.

So basically I’ve tried to find a way to drop multiple items to a script and have it send each one to the dropbox one at a time.

Any thoughts?

This is what I have and it says "Can’t set name of alias . . . " when dropping files onto the droplet.


on open fileList
	if fileList is {} then
		display dialog "Drop files onto this application to zip them." buttons {"OK"}
	else
		tell application "Finder" to set zipFolder to (container of (item 1 of fileList)) as alias
		tell application "Steps "
			launch
			repeat with i in fileList --repeat for each item
				set name of item 1 in fileList to name of (info for i)
				open item i in fileList --repeat for each item
				repeat
					exit repeat
				end repeat
			end repeat
		end tell
	end if
end open

Mate, that is it!! Thanks for the help!! :cool: