将具有某些扩展名的文件移动到计算的子目录

时间:2018-03-21 17:11:17

标签: applescript

道歉,如果这是一个可怕的问题,但我尝试搜索并提出了一些对我不起作用的结果。我是Applescript世界的新手,但是他努力让自己能够更轻松地完成一些工作。

我正在尝试编写一个

的代码

1)在Finder

中查找所选文件夹中特定扩展名的所有文件

2)根据源文件夹和预设的子目录结构确定目标文件夹

3)将带有扩展名X的文件移动到相应的文件夹

逻辑上看起来相当简单,但我缺乏理解让我觉得这很困难。在下面找到我的代码。它适用于第二个tell,并显示正确的测试路径对话框。但是我收到了错误 -

"无法得到..."的所有文件。对于sourceFolder。

有什么想法?

tell application "Finder"

set sourceFolder to POSIX path of ((target of front Finder window) as text)

end tell

set subPath to "TestPath/TestPath/"

set destFolder to sourceFolder & subPath

-- folders to sort into
set rawPath to destFolder & "RAW/"
set xmpPath to destFolder & "RAW/"
set tiffPath to destFolder & "TIFF/"

--extension list
set rawExt to {".nef", ".NEF", ".dng"}
set xmpExt to {".xmp"}
set tiffExt to {".tif"}

set testName to tiffPath & "TestFileName" & tiffExt

display dialog testName


tell application "Finder"

    repeat with eachFile in every file in sourceFolder
        if name extension of eachFile is in rawExt then
            move file eachFile to rawPath
        else if name extension of eachFile is in xmpExt then
            move file eachFile to xmpPath
        else if name extension of eachFile is in tiffExt then
            move file eachFile to tiffPath
        end if
    end repeat
end tell

1 个答案:

答案 0 :(得分:0)

这是使用HFS路径的脚本版本。

还有另一个主要问题:必须在没有前导点的情况下声明列表中的扩展名。

tell application "Finder"
    set sourceFolder to ((target of front Finder window) as text)
end tell

set subPath to "TestPath:TestPath:"

set destFolder to sourceFolder & subPath

-- folders to sort into
set rawPath to destFolder & "RAW:"
set xmpPath to destFolder & "RAW:"
set tiffPath to destFolder & "TIFF:"

--extension list
set rawExt to {"nef", "NEF", "dng"}
set xmpExt to {"xmp"}
set tiffExt to {"tif"}

set testName to tiffPath & "TestFileName" & tiffExt

display dialog testName


tell application "Finder"

    repeat with eachFile in (get every file in folder sourceFolder)
        if name extension of eachFile is in rawExt then
            move eachFile to folder rawPath
        else if name extension of eachFile is in xmpExt then
            move eachFile to folder xmpPath
        else if name extension of eachFile is in tiffExt then
            move eachFile to folder tiffPath
        end if
    end repeat
end tell