Applescript删除文件,该名称不包含" _s"

时间:2017-03-07 22:13:46

标签: applescript automator

我是一名完全使用AppleScript的新手,所以说... 我想要做的是删除文件夹中的特定文件。例如:

我有这些文件:

  • C9361WL_1.jpg
  • C9361WL_1.jpg
  • C9361WL_2.jpg
  • C9361WL_3.jpg
  • C9361WL_4.jpg
  • C9361WL_1_s.jpg
  • C9361WL_2_s.jpg
  • C9361WL_3_s.jpg
  • C9361WL_4_s.jpg

我想要删除不包含" _s"的文件。在名称文件中。

提前感谢您的帮助。

我在Automator中编写的代码是:

on run {input, parameters}
    repeat with this_file in input

        if this_file does not contain "_s" then
            delete this_file
        end if
    end repeat
    return input
end run

这个脚本仍然没有运气,我已经做了一些改变

on run {input, parameters}
    repeat with this_file in input
        set thePath to POSIX file of this_file as alias
        set delFiles to (every file of thePath whose name does not contain "_s")
        tell application "Finder"
            move files of delFiles to "/Users/dyohanan/Desktop/"
        end tell
    end repeat
    return input
end run

1 个答案:

答案 0 :(得分:1)

差不多,但您需要告诉Finder执行删除操作,并且您要检查文件的名称

on run {input, parameters}
    repeat with this_file in input
        tell application "Finder"
            if name of this_file does not contain "_s" then
                delete this_file
            end if
        end tell
    end repeat
    return input
end run