Similar to the problem described here, I have a text file with filenames, and a folder with image files that need to be copied to another destination. As these are hundreds of files quite frequently, it would help a lot to automate this task.
The challenge is that some files in the text file might not exist, and the current version of the script I have can not account for this case and throws an error.
In summary, I would like to use Automator & Apple Script to:
- ask for a source folder with the original files
- ask for a destination folder where they should be copied to
- ask for a text file with the file names
- read the names from the text file
- [new] check if a matching file exists and copy it to the destination
- [new] if there is no matching file skip the line and move on to the next one
Here's what I have so far - this works as long as there is an actual image for every line in the text file:
And AppleScript:
on run {input, parameters}
set imgDestination to input's item 2
set imgSource to input's item 1
set imgNameFile to choose file with prompt {"Select file of image filenames:"}
set imageList to every paragraph of (read imgNameFile)
repeat with eachName in imageList
tell application "Finder"
set targetImageFile to item 1 of (get every file in folder imgSource whose name = (eachName as text))
duplicate targetImageFile to folder imgDestination
end tell
end repeat
return input
end run
Unfortunately my skills are not enough to come up with a if/else scenario for 5 & 6, so any help would be much appreciated.