I am trying to move files from 1 folder to a certain folder if they have a specific name. The listOfFiles are the files to be moved.
I am getting an error cant make Can’t make {\"file1.rtf\", \"file2.rtf\", \"file3.rtf\"} into type integer
I haven't made the condition to check the name yet. first trying to just move the files.
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
Thanks!
The main problem is that you can't specify a list of strings (goFiles
) with a single file
specifier.
Assuming you want to copy all files from folder moveTest1
to folder moveTest2
whose file names are in listOfFiles
you can filter those files in one line:
set goFiles to every file of sourceFolder whose name is in listOfFiles
Since the desktop folder is the root folder of the Finder
you don't need to specify the desktop folder explicitly.
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
Actually you can write the move
operation in a single line
tell application "Finder" to move (every file of folder "moveTest1" whose name is in listOfFiles) to folder "moveTest2"