How to get the "before and after" filename

Started by EdP, February 16, 2025, 12:45:20 PM

Previous topic - Next topic

EdP

Hi,

I've tried to dig through the entire documentation, but unfortunately, I'm feeling a bit dumb.  :-[
What I have so far is a bash-script with an exiftool-command that does nearly what I want:
exiftool -m '-filename<DateCreated' -m '-filename<createdate' -m '-filename<DateTimeOriginal' -d IMG_%Y%m%d_%H%M%S%%-c.%%le "-filemodifydate<DateCreated#" "-filemodifydate<createdate#" "-filemodifydate<DateTimeOriginal#" -progress "$file"
In other words, make a decent filename from DateTimeOriginal, or if that is not present then createdate, or if that is not present then DateCreated. And the file's last modified date is also restored (I've been copying to/from different cloud storage providers so the dates were no longer original).

BUT ... what I still would like to have is a before/after reference. Because as the filename is being rewritten, I have no idea which one of all the files IMG_YYYYmmdd_HHMMSS.jpg for example, used to be HelloWorld.jpg. I've tried the -p and -w options, but either I'm doing it the wrong way, or it won't work for me.
I've even tried isolating the file in a new, empty folder, but that obviously doesn't work well when you have more than 1 file with the same timestamp (i.e. exiftool will not know to apply a -c suffix to make  unique filenames). Should I revert to putting the original filename into comments?

In short: please help.

P.S. another strange phenomenon that I observed sometimes is that the new filename in one conversion was different from a second run, eventhough I use the same filename source tags. Certainly not always, but I've noticed that in one batch some or a lot of the filenames were off by a couple of seconds. In the next run on the same batch, the time was corrected back. When you merge those files, you end up with many duplicates.

StarGeek

#1
You can add the -progress option and exiftool will output the name changes
C:\>exiftool -echo "Renaming files" -progress "-filename<Datetimeoriginal" -d "%Y-%m-%d_%H.%M.%S%%+c.%%e" -fileorder SubSecDateTimeOriginal Y:\!temp\x\y\MyFile.jpg
Renaming files
======== Y:/!temp/x/y/MyFile.jpg [1/1]
'Y:/!temp/x/y/MyFile.jpg' --> 'Y:/!temp/x/y/2025-02-16_11.21.19.jpg'
    1 image files updated

I just noticed that you have the -progress option in your command. You could redirect the output into a file to save it
exiftool -progress "-filename<Datetimeoriginal" -d "%Y-%m-%d_%H.%M.%S%%+c.%%e" file.jpg >renameList.txt

But I would suggest first running a command to save the filename into the file first. The PreservedFileName is the standard tag for this
exiftool "-PreservedFileName<Filename" /path/to/files/

Only one -m (-ignoreMinorErrors) option is needed in the command. Multiple -m does nothing beyond the first.

Quote from: EdP on February 16, 2025, 12:45:20 PMP.S. another strange phenomenon that I observed sometimes is that the new filename in one conversion was different from a second run, eventhough I use the same filename source tags. Certainly not always, but I've noticed that in one batch some or a lot of the filenames were off by a couple of seconds. In the next run on the same batch, the time was corrected back. When you merge those files, you end up with many duplicates.

We would have to see some examples of this because the command as written wouldn't change the names (except for the copy number) and certainly not off by seconds. The only reason things would be different would be files that have the exact same time down to the second and then only the copy number would change. That's because file-1.jpg would sort before file.jpg. The minus sign - has a character value of 45, with the dot has a value of 46. So these files would probably flip back and forth.

This could be avoid by using the -FileOrder option and the date/time tags that include the subseconds (see the Composite tags page)
-fileorder SubSecDateTimeOriginal
"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

EdP

Thanks for your quick reply.

Okay, so I will ditch the multiple -m's

Interestingly, I've never seen that type of old/new filename before in the -progress output. It's always been something like this:
======== IMG_20180103_170113.jpg [1/1]
Warning: Error rebuilding maker notes (may be corrupt) - IMG_20180103_170113.jpg
    1 image files updated
And yes, I see a lot of these maker notes errors lately, I guess it has to do with the multiple conversions. Anyway, it's just a warning, so I don't mind.

I am running a Linux Mint 21 box (had the same experience also in other editions) with exiftools version 12.40. Don't exactly remember how I got it, possibly through Synaptic. Pretty sure I didn't need to make it from the tarball.

I can't say exactly how the "off by seconds" file became the way it is (I've literally converted 100's of thousands of images the last few days). But it was consistently the same exiftool command listed in my first post. If I come across a newly created instance, hopefully I can save it for you. And of course I have quite a few existing instances available.

EdP

Regarding the PreservedFileName idea, I'm afraid that won't work for me, because my disk is nearly full with some 60.000 photos and videos about to be converted and uploaded to the cloud. There's no space available for extra copies. I could of course keep a directory listing like
find . -exec ls -l1 '{}' \; > filelist.txt.

The problem remains though, that I have no cross-reference, other than the file size, which is sub-optimal. I would like to know how to get that before/after line like in your -progress example, because that would give me the cross-reference I'm looking for. Is that something that was introduced in versions later than 12.40?

StarGeek

Quote from: EdP on February 17, 2025, 06:16:37 AMThere's no space available for extra copies.

I wasn't talking about extra copies. I was saying you would embed the data into the file. That way it is never lost.
exiftool "-PreservedFileName<Filename" /path/to/files/

QuoteIs that something that was introduced in versions later than 12.40?

Yes. You really should update. That version is three years old. There have been 79 updates since then.
"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

EdP

OK, good to know, but unfortunately, version 12.40 is what the repository of my Linux distro currently offers. I don't suppose you are affiliated in any way with the person(s) who maintain it for the various Linux distributions?
Perhaps I should build my own new version manually then.

Embedding the original filename sounds good to me. I tried your example and ended up with duplicate copies, with "_original" appended to the filename, that's why.

StarGeek

Quote from: EdP on February 17, 2025, 01:44:48 PMPerhaps I should build my own new version manually then.

From the author of exiftool
Quote from: Phil Harvey on July 12, 2019, 07:57:58 AMNote that it is not necessary to build ExifTool, so the entire "make" process may be skipped as long as you unpack the distribution and place "exiftool" and its "lib" directory together somewhere in the path.

There is no build needed. Figure out where the current exiftool script and library files are, download the current version from the main page, extract and drop them to overwrite the current files. Or delete those files and extract the new ones to a directory that's included in the PATH.

QuoteEmbedding the original filename sounds good to me. I tried your example and ended up with duplicate copies, with "_original" appended to the filename, that's why.

Add the -overwrite_original option to suppress the creation of backup files.
"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

EdP

Thanks for the update on the "build" part, that will make it easier.

I've just re-run a previously converted batch and captured the diffs. These all look sane to me, because it's just renumbering some of the suffix count numbers: 2019-diffs.txt

EdP

Pretty cool! I got the current version installed and I found the verbose option, which renders the input and output filenames. That's pretty useful, because not only do I get what I was looking for, I can now run the exiftool in batch mode (dir argument) rather than running exiftool for each file separately.  :)

Thanks for your help.

StarGeek

Quote from: EdP on February 17, 2025, 03:14:25 PMI can now run the exiftool in batch mode (dir argument) rather than running exiftool for each file separately.

This was always an option, not a new one.
"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

EdP

Of course, I know that, but in my use case, my bash-script had to convert 1 file at a time in order to conditionally take further action, but now I can run the entire folder (even recursively) and collect the cross-reference afterwards.

Skids

QuoteBUT ... what I still would like to have is a before/after reference. Because as the filename is being rewritte

I use  -verbose which among other things lists old and new filenames in the log file.