importing from .csv multiple files in different directories/folders

Started by sharppixels, August 07, 2023, 07:50:54 PM

Previous topic - Next topic

sharppixels

Thanks for creating such a great tool!

I'm using version 12.0, and I've got files spread out across different nested folders, and I'm trying to update their metadata from a single .csv file

Here's an example of the folders/files structure:
Macintosh HD
  Test
    2023
      Aug
        06
          abc.jpg
        07
          xyz.jpg


I've got a csv file formatted like this
SourceFile, year
/Test/2023/Aug/06/abc.jpg, 2023
/Test/2023/Aug/07/xyz.jpg, 2023


When I run my command with -v2, it outputs 
exiftool -csv=/myFiles.csv -sep ',' .
Imported entry for '/Test/2023/Aug/06/abc.jpg' (full path: '/Test/2023/Aug/06/abc.jpg')
Imported entry for '/Test/2023/Aug/07/xyz.jpg' (full path: '/Test/2023/Aug/07/xyz.jpg')
    1 directories scanned
    0 image files read


Is it possible to use 1 csv file to batch multiple files when they're in different folders?

Any help would be greatly appreciated

Phil Harvey

You need to specify the root directory on the command line.  If you were in the /Test directory, then "." should be fine, but "/Test" would work from any directory.  However, in either case you need to add -r to recurse into subdirectories.

But your CSV file will probably need some changes.  First, the column headers must be names of the tags you want to write.  "year" is not a tag that you can write to a jpg file.  Second, you shouldn't have spaces after the comma separators in the CSV file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

(Too slow, but posting anyway)

The CSV file is not a list of files for exiftool to process.  It's a look up table that it uses when reading files to process.

Since your files are in subdirectories, you would need to use the -r (-recurse) option for exiftool to find those files.  So your command should have been something like
exiftool -r -csv=/myFiles.csv -sep ',' /Test/

Now, a couple more possible problems.  The -sep option isn't used to define the character separating the columns. Exiftool defaults to a comma , but this may be changed with the -csvDelim option.

Instead, the -sep options is used for list type tags, such as Keywords or Subject.  Without it, the data in the CSV file for list type tags would be entered as a single string rather than multiple entries.

Also, the headers must be the name of actual tags. A column of "Year" won't write any data.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sharppixels

Thank you both so much!
I will give this a try and post back here my result

sharppixels

Thanks again!
Your much appreciated guidance worked well in solving this.
We're writing custom xmp metadata, so a config was also added

In our production environment, we'll have thousands of folders and hundreds of thousands of images, so what I ended up doing was to list out the folders that needed to be scanned and added them to the end of the command.

exiftool -config 'path/to/config' -r -csv='/path/to/csv/' -sep ',' /Test/2023/Aug/06 /Test/2023/Aug/07 /Test/path/to/other/folder
Is there a better or more efficient way to do this when there could be thousands of images in the csv file?

StarGeek

In the case of the first two example directories, using /Test/2023/ and the -r (-recurse) option should work.

Another option would be load the CSV into a spreadsheet, copy the first column and paste it into a text file, removing the header and making sure there isn't any quotes or extra trailing characters.  You could then pass the text file directly to exiftool with the -@ (Argfile) option.

Example using LibreOffice


In this case, the text file is "temp.txt" and the command to read that file list would be
-@ temp.txt
There would be no need for any other filenames/paths on the command line.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sharppixels


sharppixels

Thank you StarGeek!
The -@ is exactly what I was needing!
Works Great!