Question

Whoo, tough one.

I have one folder with photos (several subfolders) and another folder (with a different subfolder-structure) containing thumbnail. Now I have to go through each file of folder one, look in the folder-structure of folder 2 if there is a file with the same name and replace it if yes.

With automator, I can filter out all images from folder 1, but how to process them in order to do the rest? Script?

Is there a way to do this completely in a script?

Thanks!

Was it helpful?

Solution

You could use a shell script like this:

find folder1 -name '*.jpg' | while read f; do
  f2=$(find folder2 -name "${f##*/}")
  [[ $f2 ]] && cp "$f" "$f2"
done

${f##*/} removes the longest pattern matching */ from the start of $f. [[ $f2 ]] is equivalent to [[ -n $f2 ]] and it tests if $f2 has non-zero length.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top