AppleScript-将文件夹从一个位置复制到另一个位置时,排除某些文件

时间:2020-07-26 00:44:23

标签: applescript

我有一个AppleScript,它正在将源文件夹的内容复制到目标文件夹。现在,我需要为此添加一些条件逻辑,以使其从源文件夹中排除某些文件,并且不会在所有文件/文件夹之间进行复制。

这是我当前的脚本:

set here to POSIX file "/Users/benny/Desktop/Projects/Source/Project1"
set there to POSIX file "/Users/benny/Documents/Masters"

tell application id "com.apple.Finder" to duplicate ¬
             every item in the folder here to there

我想添加一些逻辑,以便它不会在这些文件之间复制:

Import.log
Recover.log

到目前为止,还没有尝试过使语法在这里工作,但是到目前为止,尚无法确定如何通过文件名排除文件。

1 个答案:

答案 0 :(得分:1)

duplicate 命令包装在try 声明中,因为如果中的there中已经存在相同的 name 。您可以取消注释with replacing并摆脱try 声明,也就是说,如果替换现有的 item 是可以的。

set here to POSIX file "/Users/benny/Desktop/Projects/Source/Project1"
set there to POSIX file "/Users/benny/Documents/Masters"

tell application id "com.apple.Finder"
    set theseItems to a reference to ¬
        (items whose name is not equal to "Import.log" and ¬
            name is not equal to "Recover.log") of folder here
    try
        duplicate theseItems to there -- with replacing
    end try
end tell