Replace Applescript查找和移动多个文件(但替换文件名中的某些字符)

Replace Applescript查找和移动多个文件(但替换文件名中的某些字符),replace,find,applescript,Replace,Find,Applescript,A我是applescript的新手。 我有一个字符串,文件名(没有后缀)用空格隔开,我可以复制它 我需要从一个文件夹中找到并移动多个与这些文件名匹配的文件。 我用以下方法解决了这个问题: -将字符串粘贴到文本编辑中 -查找并替换“带逗号的空格” -运行以下代码: set fileContents to read (choose file with prompt "Choose a comma-delimited text file") set theText to result set Appl

A我是applescript的新手。 我有一个字符串,文件名(没有后缀)用空格隔开,我可以复制它

我需要从一个文件夹中找到并移动多个与这些文件名匹配的文件。 我用以下方法解决了这个问题: -将字符串粘贴到文本编辑中 -查找并替换“带逗号的空格” -运行以下代码:

set fileContents to read (choose file with prompt "Choose a comma-delimited text file")
set theText to result
set AppleScript's text item delimiters to ","
set theTextItems to text items of theText
set AppleScript's text item delimiters to {""}
theTextItems
set theSourceFolder to (choose folder with prompt "Choose source folder") as string
set theDestination to (choose folder with prompt "Choose destination folder")
repeat with theEPSName in theTextItems
    tell application "Finder"
        set theEPSFile to theSourceFolder & theEPSName
        move file theEPSFile to folder theDestination with replacing
    end tell
end repeat
我想自动化从复制文件名字符串到移动文件的整个过程

最佳解决方案: -脚本从我的剪贴板抓取字符串(而不是“用提示选择文件”) -运行“查找并用逗号替换”“空格” -继续查找和移动文件

次优解决方案: -我将文件名保存到文本编辑中 -用“逗号”查找并替换“空格”集成到applescript中

有没有具备巫师知识的人来帮我? 那太棒了

(剪贴板为文本)
将以字符串形式提供剪贴板内容

如果空白是原始分隔符,您只需执行
(剪贴板中的单词作为文本))
并跳过带有逗号和文本项分隔符的步骤

words of
不关心“单词”之间有什么空格,或者有多少空格。它可以是空格、制表符、回车符、换行符,可能还有其他一些东西,以任何顺序排列,所以您可以非常自由地格式化输入

如果每行有一个文件名,可以使用的
段落,以防文件名中包含空格,这可能会更安全

你的文本输入来自哪里?你也许也能为这一部分编写脚本。例如:

tell application "Finder" 
    set matches to (name of (files of window 1 whose name contains "foo"))
end tell
剪贴板上的内容似乎是一个危险的东西,但可以依赖

试着这样做:

set theSourceFolder to (choose folder with prompt "Choose source folder") as string
set theDestination to (choose folder with prompt "Choose destination folder")
repeat with theEPSName in (words of (the clipboard as text))
    tell application "Finder"
        set theEPSFile to theSourceFolder & theEPSName
        move file theEPSFile to folder theDestination with replacing
    end tell
end repeat

设置文件内容以获取剪贴板将文本设置为结果将AppleScript的文本项分隔符设置为“”将文本项设置为文本项将AppleScript的文本项分隔符设置为{“”}将文本项设置为源文件夹(选择提示为“源文件夹”的文件夹)设置为字符串将目标设置为(选择提示为“目标文件夹”的文件夹)重复文本项中的psname告诉应用程序“Finder”将psfile设置为source文件夹&psname将psfile移动到destination文件夹,替换end-tell-end repeats,这类工作。。。。!但不知怎的,我得到了一个错误:-因此,如果文本中有一个文件名,而文件夹中没有文件,脚本将停止。我能解决这个错误吗?Behause它开始从文件夹中移动所有文件,直到有一个不存在的文件名。将移动包装在if语句中。类似于
的内容,如果文件theEPSFile存在,则将文件移动到epsfile end,如果