1

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?

4

3 回答 3

2

好吧,所以我仍然对这个问题感到困惑。我创建了一个 Bash 脚本,它通过一个只有一行代码的 Applescript 可执行文件执行:

执行 shell 脚本“/Volumes/Work/createZipFile.sh”

Bash 脚本打开 Applescript,它让我提示一个文件夹(我知道,打开 AS 来运行运行 AS 的 Bash 脚本有点傻)。然后使用该变量压缩此文件夹内容,而不使用 .fla 文件。

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

告诉应用程序“Finder”

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

结束告诉返回(我的文件夹的posix路径)EOT`

cd $我的文件夹

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

echo "已创建 zip 文件"

所以这个脚本确实适用于我尝试压缩的一些文件夹。但不幸的是,并不是我选择的每个文件夹。有时(不知道为什么)它似乎找不到我在提示符下选择的文件夹,所以我开始(至少压缩过程开始疯狂地运行并且不会停止)压缩我的整个驱动器。有什么想法可能是错的吗?

于 2013-07-23T15:14:52.987 回答
1

如果有人想使用这个脚本(我非常怀疑;)),这是我的最终版本。

#!/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
于 2013-07-24T09:03:36.020 回答
0

您的第一步应该是弄清楚 .fla 是什么“种类”文件。为此,请运行此脚本并选择您的 .fla 文件之一:

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

然后要获取在任何文件夹中键入的所有文件,您可以运行此脚本(将“纯文本”替换为您的 .fla 的任何类型):

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

从那里它只是一个拉链的问题。在进行了一些快速的谷歌搜索之后,看起来从 applescript 压缩的最简单方法是使用 do shell 脚本,既然您在一个漂亮的小数组中拥有所需的所有文件,这应该不会那么糟糕。不过,如果您追求速度,我可能会建议将整个项目转移到 bash。这也应该简化很多事情。祝你好运!

于 2013-07-22T17:21:11.357 回答