【问题标题】:Copy the files from one folder to another folder using applescript got an error使用applescript将文件从一个文件夹复制到另一个文件夹时出错
【发布时间】:2020-11-18 06:06:48
【问题描述】:

我正在尝试使用以下代码将文件从一个文件夹复制到另一个文件夹。

在运行{输入,参数}

set collectPaths to {}
repeat with i from 1 to (input count)
    set collectPaths to item i of input as string
end repeat

tell application "System Events"
    set fileList to (every folder of folder collectPaths whose name is "Old")
    if (count of fileList) is equal to 0 then
        tell application "Finder"
            set x to make new folder at input with properties {name:"Old"}
        end tell
    else
        set x to fileList
    end if
end tell

tell application "System Events"
    set fileList to (every file of folder collectPaths whose name extension is "ai")
    repeat with i from 1 to count of fileList
        set theItem to item i of fileList
        tell application "Finder"
            duplicate the file theItem to the folder x
        end tell
    end repeat
end tell

结束运行

但我得到一个错误 “操作“运行 AppleScript”遇到错误:“Finder 出错:无法为文件夹“无标题文件夹 2”的文件夹“桌面”的文件夹“旧”创建别名将启动盘文件夹“Users”文件夹“asuvathdhamank”的“输入字符串。”

请帮我解决这个问题并复制旧文件夹中的文件

【问题讨论】:

    标签: applescript


    【解决方案1】:

    首先,您的第一个循环毫无意义。在出口处,CollectPath 将包含输入的最后一项,并且不执行任何其他操作。要运行输入元素,只需使用这个:

    repeat with collectPaths in inputs
       display dialog "Hello, " & collectPaths
       -- put your whole routine in this loop
    end repeat
    

    如果需要,只需创建一个新文件夹(无需检查它是否存在):

    do shell script "mkdir -p" & space & quoted form of (posix path of collectPaths & ":Old")
    

    您必须熟悉“引用形式”和“posix 路径”、“posix 文件”、HFS 和 POSIX 路径。任何地方都有很多例子。您可以在脚本编辑器库中浏览 StandardAdditions 字典以了解这些术语。

    您必须弄清楚“输入”中的内容是路径列表还是路径? 在脚本中的关键点放置“log input”、“log class of input”、“log collectPaths”,以了解更多关于正在发生的事情。

    祝你好运..

    【讨论】:

    • 感谢您的检查和您的 cmets,我将执行您的建议,如果我有任何错误,请告知
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 2023-01-14
    • 2017-07-23
    • 2013-05-21
    相关资源
    最近更新 更多