这是我第一次尝试使用AppleScripting。
我有3个包含图像文件的文件夹。 测试文件夹1有77个大型主文件。 测试文件夹2在名为ABC的子文件夹中有4个较小的文件,其名称与测试文件夹1中的文件同名。 测试文件夹3包含一个名为ABC的空子文件夹。 我想要一个脚本检查测试文件夹2中的文件名,并将等效文件名从测试文件夹1复制到测试文件夹3子文件夹ABC
这是我到目前为止所做的:
tell application "Finder"
set the_files to (files of folder "Macintosh HD:Users:Ronnie:Pictures:Test Folder 1:")
set the_file_names to (files of folder "Macintosh HD:Users:Ronnie:Pictures:Test Folder 2:ABC:")
set target_folder to ("Macintosh HD:Users:Ronnie:Pictures:Test Folder 3:ABC:")
if document files of the_file_names is equal to document files of the_files then duplicate the_files to target_folder
end tell
目前它将复制测试文件夹1中的所有文件,使其接缝为" If"脚本不起作用。
有人可以帮忙吗?
罗尼
答案 0 :(得分:0)
这是一种方法。
--this is my preference. I prefer to work with strings then coerce them to aliases
--"aliases" in the old AppleScript/Mac API sense, meaning special file/folder path data type
-- (this is what is returned when you use the choose file or choose folder commands, e.g.)
-- aliases can be coerced to and from strings
-- not to be confused with POSIX style paths which use "/" as separator, OR
-- Finder item objects, which are specific to the Finder ('file x of folder y of startup disk z' style)
set tf1 to "Macintosh HD:Users:Ronnie:Pictures:Test Folder 1:"
set tf2 to "Macintosh HD:Users:Ronnie:Pictures:Test Folder 2:ABC:"
set target_folder to "Macintosh HD:Users:Ronnie:Pictures:Test Folder 3:ABC:"
--above not needed in Finder tell block
tell application "Finder"
set fileNames to (name of files of alias tf1) --we get the names of the files here; "name" filters, so does "files"
set matchNames to (name of files of alias tf2) --and the names of the files we want to match in testing
repeat with thisName in fileNames --repeat loop is necessary for this
if thisName is in matchNames then
--notice the concatenating of folder and name to make new alias that gets copied
duplicate alias (tf1 & thisName) to alias target_folder
end if
end repeat
end tell