MacOS – simple script to duplicate files into a new folder based on a csv file

automationmacos

Our challenge is that we need to search and duplicate approx 3000 images into a new folder.

The list of image names is a csv file. The files are all on one drive, but in many different folders.

Best Answer

Using Bash:

#!/bin/bash

cat /path/to/file.csv | while IFS=, read col1 col2 col3
do
    find . -path "$col1" -exec cp {} /DESIRED/DIRECTORY \;
done
  • IFS is the input field separator. Declare as , for .csv.
  • find . -path searches through your home directory recursively for names read from col1, returning the full path.
  • exec executes the cp command on {}, which represents all the results find returns
  • the files are copied to /DESIRED/DIRECTORY and \; is required for terminating the exec command