【问题标题】:Applescript to delete a file, that name does not contain "_s"Applescript 删除文件,该名称不包含“_s”
【发布时间】:2017-03-10 03:46:30
【问题描述】:

我是一个完全使用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

【问题讨论】:

    标签: applescript automator


    【解决方案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
    

    【讨论】:

    • 嗨 vadian,感谢您的帮助。我按照你说的做了,现在我收到一条错误消息告诉我:语法错误:“不能将项目 1 的名称转换为类型引用”
    • 脚本假定input 是一个别名说明符列表。
    • 你是对的,当我只用一个项目而不是一个列表进行测试时,错误就出现了。但现在我没有收到错误,但脚本没有删除文件。
    猜你喜欢
    • 2018-03-11
    • 2011-09-27
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多