Applescript 如何将文件从一个文件夹移动到另一个文件夹。不能变成类型整数错误
Applescript how to move files from 1 folder to another. Can’t make into type integer Error
我正在尝试将文件从 1 个文件夹移动到某个文件夹(如果它们具有特定名称)。 listOfFiles 是要移动的文件。
我收到一个无法生成的错误无法将 {\"file1.rtf\"、\"file2.rtf\"、\"file3.rtf\"} 转换为整数类型
我还没有提出查询名字的条件。首先尝试移动文件。
set listOfFiles to {"file1.rtf", "file2.rtf","file3.rtf"}
tell application "Finder"
set sourceFolder to ((path to desktop) & "moveTest1") as string as alias
set goFolder to ((path to desktop) & "moveTest2") as string as alias
set goFiles to the name of every file of sourceFolder
repeat with i from 1 to the count of goFiles
if goFiles = listOfFiles then
move file goFiles to folder goFolder
end if
end repeat
end tell
谢谢!
主要问题是您无法使用单个 file
说明符指定字符串列表 (goFiles
)。
假设您要将所有文件从文件夹 moveTest1
复制到文件夹 moveTest2
,其文件名在 listOfFiles
中,您可以在一行中过滤这些文件:
set goFiles to every file of sourceFolder whose name is in listOfFiles
由于桌面文件夹是 Finder
的根文件夹,因此您无需明确指定桌面文件夹。
set listOfFiles to {"file1.rtf", "file2.rtf", "file3.rtf"}
tell application "Finder"
set sourceFolder to folder "moveTest1"
set goFolder to folder "moveTest2"
set goFiles to every file of sourceFolder whose name is in listOfFiles
move goFiles to goFolder
end tell
其实你可以把move
操作写在一行
tell application "Finder" to move (every file of folder "moveTest1" whose name is in listOfFiles) to folder "moveTest2"
我正在尝试将文件从 1 个文件夹移动到某个文件夹(如果它们具有特定名称)。 listOfFiles 是要移动的文件。
我收到一个无法生成的错误无法将 {\"file1.rtf\"、\"file2.rtf\"、\"file3.rtf\"} 转换为整数类型
我还没有提出查询名字的条件。首先尝试移动文件。
set listOfFiles to {"file1.rtf", "file2.rtf","file3.rtf"}
tell application "Finder"
set sourceFolder to ((path to desktop) & "moveTest1") as string as alias
set goFolder to ((path to desktop) & "moveTest2") as string as alias
set goFiles to the name of every file of sourceFolder
repeat with i from 1 to the count of goFiles
if goFiles = listOfFiles then
move file goFiles to folder goFolder
end if
end repeat
end tell
谢谢!
主要问题是您无法使用单个 file
说明符指定字符串列表 (goFiles
)。
假设您要将所有文件从文件夹 moveTest1
复制到文件夹 moveTest2
,其文件名在 listOfFiles
中,您可以在一行中过滤这些文件:
set goFiles to every file of sourceFolder whose name is in listOfFiles
由于桌面文件夹是 Finder
的根文件夹,因此您无需明确指定桌面文件夹。
set listOfFiles to {"file1.rtf", "file2.rtf", "file3.rtf"}
tell application "Finder"
set sourceFolder to folder "moveTest1"
set goFolder to folder "moveTest2"
set goFiles to every file of sourceFolder whose name is in listOfFiles
move goFiles to goFolder
end tell
其实你可以把move
操作写在一行
tell application "Finder" to move (every file of folder "moveTest1" whose name is in listOfFiles) to folder "moveTest2"