MacOS – OS-X: How to copy files according to their file types from an external hard drive onto an OS-X computer

automatorcopy/pastefilemacos

I have a lot of files (music, pictures, documents) on an external hard drive that I want to copy into the respective folders on OS-X. I would like to automate the copying process and put all .bmp, .jpg and .jpeg into the pictures folder on OS-X, .mp3 into music and so on for all the different file types.

How can I automate this and what software could I use?

Best Answer

One option would be to run the following script in Terminal

#!/bin/bash

find /Volumes/NAME_OF_EXTERNAL_DRIVE -type f -print | while read f; do
    case "$f" in
       *.jpg) cp "$f" "~/Pictures/${f##.*/}"
              ;;
       *.mp3) cp "$f" "~/Music/${f##.*/}"
              ;;
       *) echo "Don't know how to handle '$f'"
          ;;
     esac
done

Add lines for additional suffixes and target folders as needed (and also keep in mind that .jpg is not the same as .JPG).