Variable missing data - Filename to date tags

Started by Limpa, December 11, 2024, 12:42:28 PM

Previous topic - Next topic

Limpa

Hi, I'm quite new to ExifTool. I have googled this specific problem and tried chatbots but have come up emptyhanded. So with no luck I turn to the experts, help greatly appreciated.  :)

Problem: I want a command line that transfers the date in the filename to the other date tags. But with a twist.

Info: For files that are missing metadata I usually have a vague guess of when that image/video was created, as thus I name them according to all my other files but supplement missing information with Xs. The format I use is YYYYMMDD_HHmmss_OTHERINFO.jpg

Example of filenames with missing information:
20220610_13XXXX_IMG1234.jpg (1)
20230710_XXXXXX_England23.mov (2)
201007XX_XXXXXX_marriageparents2010.mp4 (3)
2003XXXX_XXXXXX.png (4)

From my research it is not possible to insert a "none"-tag where data is missing so I would be fine with zeroes in most cases. Please correct me if I'm wrong.

The problem I have is that I can't create a command that take all variables of missing information into account. For example file number (2) would be easy to solve if I just grab the first 8 digits and then added in 000000 for HHmmss. However, that command won't work for (3) and (4) as it is missing more information than file number (2).

Another problem I have encountered is that ExifTool tries to take missing information elsewhere. As for file number (1) it may use the "1234" of the filename as minutes and seconds. That I want to avoid and limit the information to the first 15 characters.

TLDR: I want to replace all of my Xs that appears within the first 15 characters of the filename with 0s and then use that for all the date meta data tags. And if possible, want it to work with different file formats (jpegs/png/movs/mp4), if that is impossible I can do it in several commands, one for each file format.

Phil Harvey

Quote from: Limpa on December 11, 2024, 12:42:28 PMFrom my research it is not possible to insert a "none"-tag where data is missing so I would be fine with zeroes in most cases.

It is actually possible, but very difficult and not advisable because you would run into problems with other software reading these values down the road.

QuoteI want to replace all of my Xs that appears within the first 15 characters of the filename with 0s and then use that for all the date meta data tags. And if possible, want it to work with different file formats (jpegs/png/movs/mp4),

The problem here is that you can't have 00 for month or day.  You need 01 for these.

I would try something like this:

exiftool "-alldates<${filename;s/XXXX_/0101_/;s/XX_/01_/;tr/X/0/}" DIR

This replaces XX for the month and day with 01, and replaces all other X's with 0, then writes this to the common date/time tags (DateTimeOriginal, CreateDate and ModifyDate).

- 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

"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

Limpa

Quote from: Phil Harvey on December 11, 2024, 01:28:19 PM
Quote from: Limpa on December 11, 2024, 12:42:28 PMFrom my research it is not possible to insert a "none"-tag where data is missing so I would be fine with zeroes in most cases.

It is actually possible, but very difficult and not advisable because you would run into problems with other software reading these values down the road.

QuoteI want to replace all of my Xs that appears within the first 15 characters of the filename with 0s and then use that for all the date meta data tags. And if possible, want it to work with different file formats (jpegs/png/movs/mp4),

The problem here is that you can't have 00 for month or day.  You need 01 for these.

I would try something like this:

exiftool "-alldates<${filename;s/XXXX_/0101_/;s/XX_/01_/;tr/X/0/}" DIR

This replaces XX for the month and day with 01, and replaces all other X's with 0, then writes this to the common date/time tags (DateTimeOriginal, CreateDate and ModifyDate).

- Phil

Huge thanks Phil! ;D  I'm not overtly familiar with commandline expressions but managed to google my way to what your line of code does, deepening my knowledge a little at least. I modified it just a little bit because it mistakenly put 01 into minutes and seconds because of the way my filename structure works.

This modified one works:
exiftool -overwrite_original "-alldates<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}"
However, I now have two new problems. This below is my folder after I run the command.


1. As you also can see in the image, the Created Date and Modified Date columns are unchanged. I can't get them to update with alldates. It does work when I change to FileCreateDate and FileModifyDate instead of AllDates so this is a minor problem and I can fix it by just running the command several times.
2. As you can see the Date Taken column is updated correctly for jpgs. The Media Created column is also filled in for video files after the command is run, and as you can see everything is 2 hours in the future (compared to the file name) which I found very weird?.

Info1: I get this warning for the jpegs but it does not seem to be relevant to problem number 2.
Warning: IPTCDigest is not current. XMP may be out of syncInfo2: The videofiles get the correct created and modified date when running problem number 1. It is just the Media Created column.


Phil Harvey

Use this command to also update the system FileCreateDate and FileModifyDate:

exiftool -overwrite_original "-alldates<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" "-filecreatedate<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" "-filemodifydate<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" -api quicktimeutc DIR
I've added -api quicktimeutc which causes CreateDate to be written as UTC to video files, and should solve your 2-hour difference problem.

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

Limpa

Quote from: Phil Harvey on December 13, 2024, 12:29:21 PMUse this command to also update the system FileCreateDate and FileModifyDate:

exiftool -overwrite_original "-alldates<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" "-filecreatedate<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" "-filemodifydate<${filename;s/XXXX_XX/0101_00/;s/XX_XX/01_00/;tr/X/0/}" -api quicktimeutc DIR
I've added -api quicktimeutc which causes CreateDate to be written as UTC to video files, and should solve your 2-hour difference problem.

- Phil

Thanks you so much Phil! You're the MVP, works like a charm  ;D