Changing taken dates in multiple subdirectories

Started by WeaselDriver, March 05, 2024, 07:43:31 PM

Previous topic - Next topic

WeaselDriver

I have thousands of images stored in a structure like "C:\Users\username\OneDrive\Pictures\Filed by Date\2023 12 28 Beaufort Christmas\2023_12_28_(15).JPG"  The Date Taken fields are mostly non-existent, but as you can see I've figured out how to name the files with a date that's close to the actual one.  I don't care about the time stamp, only the date.  I'm trying to use exiftool to add a date taken that matches the filename and have had some success with this code in some test directories (forgive my sloppiness—it's been almost 25 years since I played with a command line or Linux):

exiftool "-alldates<${filename;s/(\d{4})_(\d\d)_(\d\d).*/$1:$2:$3 $4:$5:$6/}" /

I do get a whole lot of "Warning: Substitution pattern not terminated for 'filename' – dir "errors but it worked for a majority of the files.

Could someone help me fix the above code and extend it so I can run it in the "Filed by Date" directory and have it run through all the subdirectories?  Many thanks in advance!

I'm on Windows 11, exiftool v. 12,77, and all the files are .jpg or .jpeg.

Phil Harvey

Are you using CMD or PowerShell?  I can't see why this wouldn't work in CMD, but I'm sure the quoting won't work for PowerShell.

To process only .jpeg and .jpg files in all subdirectories, add -ext jpg -ext jpeg -r

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

WeaselDriver

First, your responsiveness is amazing!  Thank you!

I'm using CMD. It still doesn't work.  I had to remove the $4, 5, and 6 because I got errors for all files: Warning: Use of uninitialized value $4 in concatenation (.) or string for 'filename' - C:/Users/edtom/OneDrive/Desktop/Temp/2023_12_28_(26).JPG (I don't know what the $4 does, anyway...cut and pasted from another forum post).  When I used

exiftool "-alldates<${filename;s/(\d{4})_(\d\d)_(\d\d).*/$1:$2:$3/}" / -ext jpg -ext jpeg -r/ C:\Users\username\OneDrive\Desktop\Temp

It gave me this warning on seven files:

Warning: [minor] Invalid CanonCameraSettings data - C:/Users/edtom/OneDrive/Desktop/Temp/2017_05_10_(240).JPG

This warning on one file:

Warning: [Minor] Duplicate XMP property: mwg-rs:Regions/mwg-rs:AppliedToDimensions/stDim:unit - C:/Users/edtom/OneDrive/Desktop/Temp/2019_05_30_(24).JPG

And results were:
    2 directories scanned
    0 image files updated
   78 image files unchanged

There are 78 files in the main directory I'm using to test and 58 in the subdirectory.  It doesn't look like it's actually seeing the files in the subdirectory.  CMD output and sample file structure images below.

StarGeek

#3
Quote from: WeaselDriver on March 06, 2024, 01:40:46 PMI had to remove the $4, 5, and 6 because I got errors for all files

I was wondering what you were doing there, as you were only capturing three values

Quote(I don't know what the $4 does, anyway...cut and pasted from another forum post)
The $4 is a capture group from the regex.  Capture groups capture data that is in the parenthesis. So $1 captures the first group of (\d{4}) which is a digit \d repeated 4 times {4}$2 is the next group of two digits, as each \d represents a single digit, etc.


QuoteWhen I used
It gave me this warning on seven files:

Warning: [minor] Invalid CanonCameraSettings data - C:/Users/edtom/OneDrive/Desktop/Temp/2017_05_10_(240).JPG

This indicates that the MakerNotes section, the Canon specific data, has been corrupted somehow. This often happens when edited by a program that doesn't properly read/write EXIF data, as the MakerNotes are located in the EXIF block

QuoteThis warning on one file:
Warning: [Minor] Duplicate XMP property: mwg-rs:Regions/mwg-rs:AppliedToDimensions/stDim:unit - C:/Users/edtom/OneDrive/Desktop/Temp/2019_05_30_(24).JPG

This just means that some program incorrectly created Region data (facial recognition regions).

Both of these can be ignored, as they won't break anything

QuoteAnd results were:
    2 directories scanned
    0 image files updated
   78 image files unchanged

There are 78 files in the main directory I'm using to test and 58 in the subdirectory.  It doesn't look like it's actually seeing the files in the subdirectory.  CMD output and sample file structure images below.

It sees the files, which is why it returns 78 image files unchanged.  The problem is that you aren't writing a proper date/time, you haven't included the time portion of the data.

Try this command in CMD. It will set a default time of Midnight 00:00:00

exiftool "-alldates<${filename;m/(\d{4}_\d\d_\d\d)/;$_=$1} 00:00:00" -ext jpg -ext jpeg -r C:\Users\username\OneDrive\Desktop\Temp

I've changed it so that it only grabs the date portion of the filename and drops everything else.  Then the 00:00:00 time is appended to that.
* 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).

WeaselDriver

Thank you again for the very prompt reply.  That got all of them with a filename formatted like 1968_01_01.JPG

However, it's throwing two different errors on the files with filenames having characters after the day indicator in the filename, like 2010_10_22_(76).JPG.  In my naming convention, there will be an underscore followed by a number up to three digits in parentheses, i.e. "_(123).jpg

Warning: Search pattern not terminated for 'filename' - C:/Users/username/OneDrive/Desktop/Temp/Subdirectory/2010_10_22_(76).JPG

Warning: No writable tags set from C:/Users/username/OneDrive/Desktop/Temp/Subdirectory/2010_10_22_(76).JPG

StarGeek

Quote from: WeaselDriver on March 06, 2024, 04:48:28 PMWarning: Search pattern not terminated for 'filename' - C:/Users/username/OneDrive/Desktop/Temp/Subdirectory/2010_10_22_(76).JPG

Ooops, my mistake.  Forgot the last slash.  I edited the post to add it.

QuoteWarning: No writable tags set from C:/Users/username/OneDrive/Desktop/Temp/Subdirectory/2010_10_22_(76).JPG

This should go away with the corrected command.
* 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).