Main Menu

File Rename Advice

Started by plumberg, January 22, 2022, 08:30:51 PM

Previous topic - Next topic

plumberg

Hello,

My First post here, apologies if the formatting is not correct or I am missing some info...

Hope you all are safe and well.

I have over 20000+ jpg images  in a folder (few .mov/ .dng/ mp4 files) .Most of them are good, but, a handful of them got messed up with the filenames when I moved them from my phone. I need some advice on what is the best way to manage and ensure files are named consistently.

There are some peculiarities and would love to see how I can safely rename each file...

If there is a way to create a list of files which are not correctly named, I could review it first? Then, I can execute the actual rename... ? Not sure if this is possible.

Thanks in advance for your help!

I am showcasing most common types of files and issues here:

exiftool.exe -FileName -DateTimeOriginal -FileSize 20170921_185933* 20170923_233000* 20201220_135650* 20171001_134251*

Files with same date-time-original... Is there a way to grab more granular time?
======== 20170921_185933(0).jpg
File Name                       : 20170921_185933(0).jpg
Date/Time Original              : 2017:09:21 18:59:33
File Size                       : 2.9 MiB
======== 20170921_185933.jpg
File Name                       : 20170921_185933.jpg
Date/Time Original              : 2017:09:21 18:59:33
File Size                       : 3.0 MiB


Files where original-date-time is different but still hold similar name

======== 20170923_233000(0).jpg
File Name                       : 20170923_233000(0).jpg
Date/Time Original              : 2017:09:23 23:30:00
File Size                       : 2.0 MiB
======== 20170923_233000.jpg
File Name                       : 20170923_233000.jpg
Date/Time Original              : 2017:09:23 23:29:59
File Size                       : 1975 KiB


Here is where the real mess happened while transferring photos...
If you see - "20201220_135650.jpg" has a completely different original-date-time vs "20201220_135650 (2).jpg" has the one matching the filename.

======== 20201220_135650 (2).jpg
File Name                       : 20201220_135650 (2).jpg
Date/Time Original              : 2020:12:20 13:56:50
File Size                       : 4.8 MiB
======== 20201220_135650.jpg
File Name                       : 20201220_135650.jpg
Date/Time Original              : 2020:12:20 12:02:01
File Size                       : 2.5 MiB


A few random files that are suffixed with _00X.jpg

======== 20171001_134251_001.jpg
File Name                       : 20171001_134251_001.jpg
Date/Time Original              : 2017:10:01 13:42:51
File Size                       : 2.2 MiB

StarGeek

Quote from: plumberg on January 22, 2022, 08:30:51 PM
If there is a way to create a list of files which are not correctly named, I could review it first? Then, I can execute the actual rename... ? Not sure if this is possible.

Run the command you want to use but use Testname instead of Filename.  If need be, capture the output to a text file to review.  For example
exiftool "-TestName<Datetimeoriginal" -d "%Y-%m-%d_%H.%M.%S%%+c.%%e" /path/to/files/ >Filelist.txt

After going over the list, you can decide if it's correct and then use Filename, or see if you need to do more work on the files.

QuoteFiles with same date-time-original... Is there a way to grab more granular time?

Maybe, it depends upon the device that took the picture.  Some cameras keep track of the sub-second.  Exiftool creates a Composite tag called SubSecDateTimeOriginal which includes the subseconds, as well as time zone if it exists.  Use that instead of DateTimeOriginal and you can add the subseconds to your format code with %f.  See Common Date Format Codes for details.
* 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).

plumberg

Thank you so much @Stargeek.

So, I have one small issue here

exiftool -FileName -DateTimeOriginal "-TestName<Datetimeoriginal" -d "%Y%m%d_%H%M%S%%+c.%%e" .


'./20201220_135650 (2).jpg' --> './20201220_135650_1.jpg'


Any reason why it would append _1 counter? Technically, it should rename to: 20201220_135650.jpg

But, If you see, the next file (has incorrect DateTimeOriginal) and its set to getting renamed correctly... And it shares the FileName of what I want the previous file to get renamed...



'./20201220_135650.jpg' --> './20201220_120201.jpg'


Any thoughts on How to handle this cyclic condition?

Thanks!

StarGeek

The counter appears because there's another file with the same time stamp.  That's what the %%+c does.

You should run the command you listed if there are files with the incorrect time stamp.  You should either fix them first or separate them from the correct ones.
* 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).

plumberg

Hmm. Since there are 10000s files in same folder its gonna be tricky to filter out files manually.  Any suggestions? Thank you


Phil Harvey

To avoid conflicts with existing file names, you should move them to a temporary directory, then move them back afterwards:

exiftool "-TestName<Datetimeoriginal" -d "tmp/%Y%m%d_%H%M%S%%+c.%%e" .

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

plumberg

Thank you Phil. Any suggestion on a decent tool that can isolate similar file names? I am scouting for some script which may do something. I guess there is no other way out. Thanks!

chuck lee

Since your file copy number is "%+c", the following command can filter out the duplicate files for further checking.

find .  -iname '*_[0-9].*' -type f -printf "%p %T@ %s\n" | sed -rn 's/(.*)(_[0-9])(\..*) (.*)(\..*) (.*)/\1\3 \1\2\3 \4 \6/p' | sort -b -s -S 10M -k 1,1 -k 3,3nr > dup_out


The dup_out file contains name of the duplicate file.  The first field is the file that has the original file name, 2nd field is the duplicate filename renamed by exiftool, 3rd field is the modifydate in seconds of the duplicate file and the last field is the size in byte of the duplicate file.  To find out the modifydate and size of the original file:

        f_sec=$(stat -c%Y "$f")
        f_size=$(stat -c%s "$f")

where $f is the original filename.