0

我需要从一个文件夹中选择一堆不同名称的文件。到目前为止,这是我必须在小范围内工作的脚本。

tell application "Finder" to select (every file of target of front window whose 
name contains "3123" or name contains "3125" or name contains 3166)

但是我需要一个可以大规模工作的脚本,我可以在其中输入类似于 myValues 的内容

set myValues to {3101, 3102, 3103, 3456, 6789, etc. etc.}
tell application "Finder" to select (every file of target of front window whose 
name contains myValues)

但是当我使用该脚本时,当我为 myValues 设置了多个数字时,它不会选择任何文件。另外,如果您能告诉我如何将其更改为与文本一起使用,那就太棒了。

感谢所有的帮助!

4

1 回答 1

2

尝试:

set myValues to {"3101", "3102", "3103", "3456", "6789"}

tell application "Finder" to set fileList to files of target of front window

set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

tell application "Finder" to select matchedFiles

编辑 - 添加了 Finder 窗口和 regulus6633 的建议:

set myValues to {"3101", "3102", "3103", "3456", "6789"}

tell application "Finder" to set fileList to files of target of front Finder window as alias list

set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

tell application "Finder" to select matchedFiles

编辑 2

set myValues to {"3125", "3123"}

tell application "Finder" to set fileList to files of target of front Finder window as alias list
set matchedFiles to {}
repeat with aFile in my fileList
    repeat with aValue in myValues
        tell application "System Events" to if aFile's name contains (contents of aValue) then set end of matchedFiles to (aFile as text)
    end repeat
end repeat

if matchedFiles ≠ {} then
    tell application "Finder"
        select matchedFiles -- you don't need to select files to duplicate them
        duplicate matchedFiles to (choose folder)
    end tell
end if
于 2013-06-11T14:35:47.833 回答