1
votes

I've got a folder with a set of images and need to copy those files into another folder, replacing any of the same name there. The images in the target folder are in subfolders.

What I thought I could do is take my list of images and drag them into another finder window that had filtered down to only the files that would be replaced (bypassing the subfolder structure in effect), but I guess osx doesn't allow that kind of copy/replace.

So I'm looking to solve this with an automator/applescript. The subfolder bit is what throws me off in automator - any help is appreciated.

example:
source_folder/file_1.jpg
source_folder/file_2.jpg
source_folder/file_3.jpg
etc...

Should copy/overwrite targets:
target_folder/subfolder_234/file_2.jpg
target_folder/subfolder_122/file_1.jpg
target_folder/subfolder_425/file_3.jpg
etc...
1

1 Answers

2
votes

This script get files in the source folder, for each filename, it search a file of same name in the subfolders of the target folder, the cp command copy and replace.

set sFolder to quoted form of POSIX path of (choose folder with prompt "Select the source folder")
set tFolder to quoted form of POSIX path of (choose folder with prompt "Select the target folder")
do shell script "find " & sFolder & " -maxdepth 1 -type f ! -name '.*' -print0 | while read -d $'\\0' f; do name=${f##*/}; find " & tFolder & " -type f -name \"$name\" -maxdepth 2 -mindepth 2 -exec cp -pf \"$f\" '{}' \\;;done"