Sunday, December 4, 2022
  • Index
  •  » Code Exchange
  •  » Short Script to Create Individual Zip Files of a selection of files

#1 2007-12-24 01:41:04 pm

generica
Member
Registered: 2006-08-25
Posts: 1

Short Script to Create Individual Zip Files of a selection of files

I wrote this really quickly this morning to create zip files of a large amount of files I had in a folder that were needed to be compressed into individual zip files. 

So, if a folder contains file1.txt, file2.txt, file3.txt you will get file1.zip, file2.zip, file3.zip respectively.  The original files remain in tact for you to do what you wish with.

This script works with Leopard's Archive Utility on OS X 10.5 or higher.  It could easily be modified to use BOMArchiveHelper instead on Tiger systems for the same effect.

Just thought I would post it online in case someone would find it useful.

Applescript:


set processFolder to choose folder with prompt "Choose Folder containing files to individually archive:"
tell application "Finder" to set theFileList to (files of entire contents of processFolder) as alias list
repeat with theFile in theFileList
   tell application "Finder" to open file (theFile as string) using path to application "Archive Utility"
end repeat


Filed under: Finder

Offline

 

#2 2022-10-02 11:25:28 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2589

Re: Short Script to Create Individual Zip Files of a selection of files

I tried @generica's script on Catalina and found that it still works.

But when the folder contains Finder-alias files or ready-made cpgz (MAC)-archives, it throws error messages, which is quite understandable. Also, the repeat loop is optional here.

I've tweaked the script as best I could, but I'm guessing there's more room for improvement. Anyway, here's my version:

Applescript:


-- script: Create individual .cpgz (MAC)- archives for files of entire contents of folder
-- Written: by @generica, apapted: by KniazidisR

set processFolderAlias to choose folder with prompt "Choose Folder containing files to individually archive:"
createCPGZarchives(processFolderAlias)

on createCPGZarchives(processFolderAlias) -- alias parameter
   set archiveUtilityID to "com.apple.archiveutility"
   tell application "Finder" to set aliasList to (files of entire contents of folder (processFolderAlias as text) whose kind is not in {"CPGZ archive", "Alias"}) as alias list
   tell application id archiveUtilityID to open aliasList
   delay 2
   tell application id archiveUtilityID to quit
end createCPGZarchives

Last edited by KniazidisR (2022-10-03 12:01:49 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 
  • Index
  •  » Code Exchange
  •  » Short Script to Create Individual Zip Files of a selection of files

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)