AppleScript查找包含特定文件

时间:2017-11-04 20:50:30

标签: macos applescript

我有一个包含文件/resources/video.mov的文件夹。带有视频的此文件夹可以位于任何位置,例如/Users/UserName/Desktop/resources/video.mov/Applications/resources/video.mov等。我需要找到包含视频的此文件夹并复制到特定位置。我找不到带视频的文件夹路径来复制它。

tell application "Finder"
    duplicate items in folder "_locatedPath_" to folder "_destiontionPath_" with replacing
end tell

1 个答案:

答案 0 :(得分:1)

这适用于我使用最新版本的Sierra

将变量destinationFolder的值更改为您选择的输出文件夹

property theContainer : missing value
property containingFolder : "resources" -- change if needed
property theSearch : "video.mov" -- change if needed
property destinationFolder : (path to desktop as text) -- change if needed

set findFile to do shell script "mdfind -name " & theSearch 

repeat with i from 1 to number of paragraphs in findFile
    set this_item to POSIX file (paragraph i of findFile) as alias
    tell application "Finder"
        if name of this_item is theSearch then
            set theContainer to the container of this_item as text
            if theContainer contains containingFolder then
                set resultObject to duplicate this_item ¬
                    to destinationFolder ¬
                    replacing true ¬
                    routing suppressed true ¬
                    with exact copy
            end if
        end if
    end tell
end repeat