Add date metadata from filename weird naming conventions (more than one style)

Started by nabil, October 12, 2023, 04:17:38 AM

Previous topic - Next topic

nabil

I recently imported a bunch of images (around 7000) from my Samsung phone, and a lot of them have some pretty weird naming conventions. I've gone through the trouble of sorting the different styles of names. Thankfully the exiftool  "-AllDates<${Filename;m/(\d{4}\d\d\d\d);$_=$1} 00:00:00" "C:\Users\PC\Desktop\testing region\pics"command has worked with most of the files that have year month date and hours minutes seconds, and gives midnight for the files that dont have time in the filename. And this is all great (even though I don't understand what the code actually means 😭, especially this part [;$_=$1]).


Anyways my question/problem is with files that have different date conventions like month date year. And Some of them have time in the filename and some don't. So I'm very confused. Here is an example. "instauser-17072022-0002". (this is date month year if anybody can't tell)

What code can I write to deal with this, and I need something that will work with a batch with a different number of letters before (for example one of my files is called "webwhatsapp-23082021-032518").

And if it's any help I already checked for missing metadata, its all been completely stripped.

StarGeek

Quote from: nabil on October 12, 2023, 04:17:38 AM(even though I don't understand what the code actually means 😭, especially this part [;$_=$1]).

The $_ is the default variable in Perl.  You can search on that for more details, but when using it in exiftool like this, it holds the value of the named tag.  In this case, Filename.  The $1 is the captured data from RegEx match.  So the result is assigning the the captured value to the tag.

QuoteAnyways my question/problem is with files that have different date conventions like month date year. And Some of them have time in the filename and some don't. So I'm very confused. Here is an example. "instauser-17072022-0002". (this is date month year if anybody can't tell)

Your command would be similar, but instead of capturing 8 numbers as a single match, you have to split it up and reorganize it.  In this case, you would use
exiftool "-AllDates<${Filename;m/(\d\d)(\d\d)(\d{4});$_=$3.$2.$1} 00:00:00" /path/to/files/

This captures the first two numbers (\d\d) as variable 1 $1, the next two numbers as variable 2 $2, and then the last four (\d{4}) as variable 3 $3.  It then reorganizes them as YearMonthDay.

QuoteWhat code can I write to deal with this, and I need something that will work with a batch with a different number of letters before (for example one of my files is called "webwhatsapp-23082021-032518").

Any command copying the Filename into a date/time tag ignore any character that isn't a number (see FAQ #5, paragraph starting "Having said this").  The problem is the extra numbers.  The commands above look for a group of 8 numbers in a row and will ignore any others.  The biggest problem is separating the ones that need to have the groups reversed.

Any other patterns would require different commands.  Technically, it would be possible to make a single command to fit most of the files, but it would require seeing an example of all the patterns.  And it would be a much more complex command and harder to troubleshoot problems.  IMO, It would be better to separate out the files by pattern and run individual commands over each group.
* 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).