2

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.

1
  • 2
    Can you add a sample of the cvs file (just a few lines)? Commented Aug 27, 2014 at 12:30

3 Answers 3

3

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
0
1

Here's a simple python script that will do the trick:

import csv, subprocess

csv_path = '/Users/mdryden/Desktop/test2/test.csv'
search_path = '/Users/mdryden/Desktop/test2/'
output_path = '/Users/mdryden/Desktop/test3/'

with open(csv_path, 'rb') as csvfile:
    dialect = csv.Sniffer().sniff(csvfile.read(1024))
    csvfile.seek(0)
    reader = csv.reader(csvfile, dialect)
    for line in reader:
        subprocess.call(["find", search_path, "-name", line[0],
                        "-exec", "cp", "{}", output_path,";"])

Set csv_path, search_path, and output_path accordingly. It it's any sort of remotely standard CSV format, it should be able to autodetect it.The CSV should have no header rows and you need to set line[0] to the number of the column containing the file names (starting at 0 for the first column).

0

I would use applescript.

Open the csv file in excel grab the files, then pass the variable to the terminal where you would execute a find command followed by a copy command to the directory of your choice.

Here is some pointers:

Loop through the csv.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.