1
votes

I need to zip the content of a folder (and all the subfolders) for hundreds of folders. Is it possible to run a command that takes all the files of a specific folder (prompt), except all the files that have a .fla extension and zip this content into one zipfile?

Right now I am copying the folder, search for all the .fla-files, then select all the files inside the folder (I have the to zip the content, not the folder) and create a zip of it (takes way too long.

I know that it is possible to use Apple Script to delete and copy files. But does this also work in the above mentioned order + zipping?

3

3 Answers

2
votes

Alright, so I was still kind of stuck with this issue. I created a Bash Script, that is executed via an Applescript executable File that has only one line of code:

do shell script "/Volumes/Work/createZipFile.sh"

The Bash Script opens Applescript which lets me prompt a folder (I know, kind of silly to open AS to run a Bash Script that runs AS). The variable is then used to zip this folders content without the .fla files.

myFolder=`/usr/bin/osascript << EOT

tell application "Finder"

activate
set myfolder to choose folder with prompt "Select the Folder that you want to zip!"

end tell return (posix path of myfolder) EOT`

cd $myFolder

zip -r ZipMe.zip . -x ".fla"

echo "A zip File has been created"

So this script does actually work for some folder I try to zip. But unfortunately not for every folder I chose. Sometimes (no idea why) it seems like it can not find the folder I chose with the prompt, so I starts (at least the zip-process starts running like crazy and doesn't stop) zipping my whole drive. Any ideas what could be wrong?

1
votes

In case anybody wants to use this script (which I highly doubt ;)), here is my final version of it.

#!/bin/bash
#Opens an applescript prompt window to select a folder
myFolder=`/usr/bin/osascript << EOT
    tell application "Finder"
        activate
        set myfolder to choose folder with prompt "Select the Folder that you want to Zip!"
    end tell
return (posix path of myfolder)
EOT`


# Terminate if the path is empty (canceled)
if [ -z "$myFolder" ];
then 
    #echo "Chose a folder!"
    exit 0
else
    #Change the directory to the above selected folder
    cd "$myFolder" 
    # Creates a ZipFile with todays date of the selected folder, neglecting the after -x listed filetypes
    zip  -r ZipFile_`eval date +%Y_%m_%d`.zip . -x "*.fla*" "*.AppleDouble*" "*.DS_Store*" 
    #echo "A zip File has been created"
fi
0
votes

Your first step should be to figure out what "Kind" of file the .fla is. To do this, run this script and select one of your .fla files:

tell application "Finder"
    set theFile to choose file
    display dialog (kind of theFile) as string
end tell

And then to get all of the files BUT that type in any folder, you can run this script (Replacing "Plain Text" with whatever type your .fla's turn out to be):

tell application "Finder"
    set thePath to choose folder
    set theFiles to get every file of folder thePath whose kind is not equal to "Plain Text"
end tell

from there it's just a matter of zipping. After doing some quick googling it looks like the easiest way to zip from applescript is by using do shell script, which shouldn't be that bad now that you have all the files you need in a nifty little array. If you're going for speed though, I might suggest moving this whole project over to bash. That should also simplify things quite a bit. Best of luck!