Rename Files from CSV

Started by Stephen Marsh, May 13, 2018, 09:29:12 PM

Previous topic - Next topic

Stephen Marsh

I have searched the site and found a lot of info on renaming files, but not from a CSV source.

I can easily update metadata such as keywords using a CSV source.

SourceFile,Subject
/path-to-file-folder/old1.jpg,Keyword-1
/path-to-file-folder/old2.jpg,Keyword-2


exiftool -sep ',' -csv='/path-to-file-folder/spreadsheet.csv' -ext jpg '/path-to-file-folder/'


However, what if I wanted to update the filename from a CSV source?

SourceFile,FileName
/path-to-file-folder/old1.jpg,new1.jpg
/path-to-file-folder/old2.jpg,new2.jpg


Does not work... I have also tried with a full absolute path to the new filename.

1 directories scanned
0 image files updated
2 image files unchanged


Phil Harvey

You're right:

            Empty values are ignored when importing (unless the -f option is
            used and the API MissingTagValue is set to an empty string, in
            which case the tag is deleted).  Also, FileName and Directory
            columns are ignored if they exist (ie. ExifTool will not attempt
            to write these tags with a CSV import).


This is a feature to prevent people from messing up their files unintentionally.

You'll have to do this some other way.

- 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 ($).

Stephen Marsh

Thanks for the reply Phil, It is a shame. I even tried writing to a different directory so that the source files would be intact as I suspected that you may have built in safeguards...

colink

Just checking I understand Phil's earlier response.

Can someone confirm that it is not possible to use exiftool to rename files from a csv file.

I have read elsewhere where someone quotes Phil's answer above to explain that exiftool will not rename files form csv.
"This is a feature to prevent people from messing up their files unintentionally."

If I have understood correctly I hope Phil will not mind my comments.

Renaming files from a .CSV list would seem like something many people would want to do.

Column1 = existing path and filename
Column2 = new path and filename

If there was concern about screwing up files the command could, by default, copy the file leaving the original, but give the option of including -overwrite_original or similar when user is certain that their csv is correct.

For now I will work on the asumption that I cannto rename files usign csv.



StarGeek

Quote from: colink on November 13, 2020, 11:59:42 AM
Can someone confirm that it is not possible to use exiftool to rename files from a csv file.

It is confirmed in Phil's post above, which is taken from the docs on the -csv option.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

hieuphamvn

I've found a solution by using PowerShell in Windows

$csv = Import-Csv -Path "Your .CSV file path.csv"
    foreach ($row in $csv) {
    Rename-Item -Path "$($row.'Old Name')" -NewName "$($row.'New Name')"
    }

- Replace "Your .CSV file path.csv" with the actual path to your .CSV file.
- Your .CSV file needs two columns: "Old Name" (current file name) and "New Name" (desired file name).
- If your picture files are in a different folder than your csv file you will need to add the path to the picture folder in front of the variable "$($row.'Old Name')". Example: "C:\Users\User\Pictures\$($row.'Old Name')"