Main Menu

Changing File Dates

Started by DnvrMike, February 13, 2021, 10:54:40 PM

Previous topic - Next topic

DnvrMike

Hello, 

Totally new to the command line, sorta getting the hang of it.  Been learning about ExifTool for about 6 hours now.
Did a Full Perl Distribution install on Win 10

Working with .jpg files, want to change all the dates to the name of the file. 

exiftool "-datetimeoriginal<filename" *
exiftool "-AllDates<filename" *

output the same results:

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\x\test>exiftool 2010_12_27_18_34_27.jpg
ExifTool Version Number         : 12.18
File Name                              : 2010_12_27_18_34_27.jpg
Directory                               : .
Warning                         : Install Win32::API for proper handling of Windows file times
File Size                       : 1096 KiB
File Modification Date/Time     : 2010:12:27 18:34:27-07:00
File Access Date/Time           : 2021:02:13 17:00:10-07:00
File Creation Date/Time         : 2021:02:13 17:00:10-07:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 4
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 4.1
Modify Date                     : 2010:12:27 18:34:27
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/15
F Number                        : 2.8
Exposure Program                : Program AE
ISO                             : 1000
Exif Version                    : 0221
Date/Time Original              : 2010:12:27 18:34:27
Create Date                     : 2010:12:27 18:34:27
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/15
Aperture Value                  : 2.8
Metering Mode                   : Average
Flash                           : Off, Did not fire
Focal Length                    : 3.9 mm
Subject Area                    : 1295 967 699 696
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 2592
Exif Image Height               : 1936
Sensing Method                  : One-chip color area
Exposure Mode                   : Auto
White Balance                   : Auto
Scene Capture Type              : Standard
Sharpness                       : Soft
GPS Latitude Ref                : North
GPS Longitude Ref               : West
GPS Time Stamp                  : 18:34:24
Compression                     : JPEG (old-style)
Thumbnail Offset                : 812
Thumbnail Length                : 4567
Image Width                     : 2592
Image Height                    : 1936
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.8
Image Size                      : 2592x1936
Megapixels                      : 5.0
Shutter Speed                   : 1/15
Thumbnail Image                 : (Binary data 4567 bytes, use -b option to extract)
GPS Latitude                    : 39 deg 35' 33.60" N
GPS Longitude                   : 104 deg 53' 45.00" W
Focal Length                    : 3.9 mm
GPS Position                    : 39 deg 35' 33.60" N, 104 deg 53' 45.00" W
Light Value                     : 3.6

I don't understand why the following does not change:

File Access Date/Time           : 2021:02:13 17:00:10-07:00
File Creation Date/Time         : 2021:02:13 17:00:10-07:00

Does the error:
Warning                         : Install Win32::API for proper handling of Windows file times
have anything to do with it?

Apologies for posting the command line window incorrectly, can't figure out how to do it right.
Thank you in advance.







StarGeek

Quote from: DnvrMike on February 13, 2021, 10:54:40 PMI don't understand why the following does not change:

File Access Date/Time           : 2021:02:13 17:00:10-07:00
File Creation Date/Time         : 2021:02:13 17:00:10-07:00

If you take a look at the Shortcuts tag page, you'll see that the AllDates shortcut writes to the three most commonly used timestamps, DateTimeOriginal, CreateDate, and ModifyDate.  It doesn't write to all the time tags, as that would be excessive, since that would write about 90+ tags, many of which you probably would never use.

If you want to write to the OS timestamps, you'll want to use FileCreateDate and FileModifyDate (see the Extra tag page).

My one suggestion would be to use the command in FAQ #3, so you get tag names, not descriptions (see FAQ #2), tags that may have duplicate names (the -a (-duplicates) option), and most importantly, the groups they belong to (-G (-groupNames) option).

You should be able to run this command to make sure Win32::API is installed.
cpanm Win32::API

But on Windows, it's usually just easier to use the executable version rather than the perl version.
"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

DnvrMike

Thank you StarGeek, most helpful.

I uninstalled perl and went with the windows executable, that did seem to fix things.

Your suggestion to get tag names and not descriptions made all the difference. 
Found out my comments are actually named XPComments so I'm able to adjust them now.
Still trying to figure out how to just add to the comment field,
exiftool -XPComment+="test" a.jpg 
I get:
Warning: Shift value for IFD0:XPComments is not a number
Nothing to do.

So hoping I'll figure that out but any advice is welcome.

Spent a lot of time on the Shortcuts tag page, https://exiftool.org/filename.html and https://exiftool.org/exiftool_pod.html

Figured out how to rename my file based on the ModifyDate, DateTimeOriginal, etc...so

a.jpg becomes
1986_03_24 16.42.28.1395700948.jpg
by using
exiftool -d %Y_%m_%d" "%H.%M.%S.%s%%-c.%%e "-filename<ModifyDate" a.jpg

That's pretty cool!  So thanks for pointing me in the right direction.

However, I'm lost trying to write from my filename to the tag.  All my file names are in this format:
1986_03_24 16.42.28.1395700948.jpg

I'd really like to set all the dates in the tags to that date because my Mom is archiving a bunch of photo albums from the 1980's and her phone uses the date she took the picture.
She's renamed all the photos to like I have above but minus the tail end.  1986_03_24 16.42.28.jpg  (most of the photos have dates, she guesses the time)
The problem is uploading them to Google Photos, Google apparently uses whatever it can find in the EXIF data that is NOT the file name.  Usually the FileCreateDate or ModifyDate. But with some wedding pix it used the Sony MetaDataDate tag.  Go figure. (again, thanks to you for the help finding the actual file names, that's how I know)  I don't know why Google does it this way.  She can't be the only one uploading old photo albums.

Anyway, if you can help with that it would be great.  I'm going to keep reading and hope I stumble on the way to do it.

Thanks again!

Mike

StarGeek

Quote from: DnvrMike on February 20, 2021, 11:28:34 PM
Still trying to figure out how to just add to the comment field,
exiftool -XPComment+="test" a.jpg

To set it to a value, you just assign it
exiftool -XPComment="This is a comment" a.jpg

If it already has data and you want to add to it, you have to use the tag copy, not assignment (see Common Mistake #5c)
exiftool "-XPComment<$XPComment and now it's longer." a.jpg

QuoteHowever, I'm lost trying to write from my filename to the tag.  All my file names are in this format:
1986_03_24 16.42.28.1395700948.jpg

I'd really like to set all the dates in the tags to that date

As long as you have 14 numbers representing Year Month Day Hour Minutes Seconds, then you can copy the filename directly to the time tag (see FAQ #5, "Having said this, ExifTool is very flexible").  The example it gives there will set the most common time tags
exiftool "-alldates<filename" /path/to/files/

QuoteThe problem is uploading them to Google Photos, Google apparently uses whatever it can find in the EXIF data that is NOT the file name.  Usually the FileCreateDate or ModifyDate.

Google photos will pick one of the following tags to sort on
EXIF:CreateDate
EXIF:DateTimeOriginal
EXIF:ModifyDate
IPTC:DigitalCreationDate+IPTC:DigitalCreationTime
PTC:DateCreated+IPTC:TimeCreated
XMP-exif:DateTimeDigitized
XMP-exif:DateTimeOriginal
XMP-photoshop:DateCreated
XMP-xmp:CreateDate
XMP-xmp:ModifyDate
GPS:GPSDateStamp+GPS:GPSTimeStamp (adjusted for local timezone)
System:FileModifyDate


The GPS and system timestamps were always used last in my testing, but otherwise it seemed to depend upon the order they actually appear in the file, which isn't something that can be controlled.  AllDates is covered by this, so it's a pretty good idea to use it.

QuoteBut with some wedding pix it used the Sony MetaDataDate tag.

That's a new one on me.  But then, I don't have any Sony pictures to test with.
"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

DnvrMike

YES! Thank you.  I had the syntax all wrong with in regards to working with the XPComments tag.  Works GREAT now. 
Unrelated, I found what looked like a bunch of machine code in the UserComment tag in a bunch of my photos. 
Those photos were not displaying correctly.
I used the same modified string to delete the UserComment and now the photos will open just fine.
So again, thank you!!

Now I have a new problem.

My first try before posting was exiftool "-alldates<filename" 
It works great for renaming ModifyDate or AccessDate or CreateDate. 

Unfortunately, Google Photos still seems to be reading the FileModifyDate or FileAccessDate or FileCreateDate.  FileModifyDate is the first tag and it does seem to read in order.

Here is an example of one of my files, google photos sorts on FileModifyDate.

======== 1936_01_01 09.01.01.jpg
ExifToolVersion                 : 12.18
FileName                        : 1936_01_01 09.01.01.jpg
FileModifyDate                  : 2021:02:26 12:13:39-07:00
FileAccessDate                  : 2021:02:26 12:13:39-07:00
FileCreateDate                  : 2021:02:26 12:06:31-07:00

ModifyDate                      : 1936:01:01 09:01:01
DateTimeOriginal              : 1936:01:01 09:01:01
CreateDate                      : 1936:01:01 09:01:01


I tried to rename with the command:

exiftool "-FileModifyDate<filename" "-FileAccessDate<filename" "-FileCreateDate<filename" .

======== 1936_01_01 09.01.01.jpg
ExifToolVersion                 : 12.18
FileName                         : 1936_01_01 09.01.01.jpg
FileModifyDate                  : 1835:12:31 09:01:01-07:00
FileAccessDate                  : 1835:12:31 09:01:01-07:00
FileCreateDate                  : 1835:12:31 09:01:01-07:00

ModifyDate                      : 1936:01:01 09:01:01
DateTimeOriginal              : 1936:01:01 09:01:01
CreateDate                      : 1936:01:01 09:01:01

I've done searched the forums for a cue as to why the dates DO change but the changed date is not even close to the filename. No luck there. 

Mike

Phil Harvey

Mike,

In general date/times before 1970 (and after 2038) give unpredictable results.  The file could not possibly have been created before then, so they are not physical either.

- 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

Can you share the file that you're having problems with?  When I test an image by setting the timestamps with this command
exiftool "-alldates=1936:01:01 09:01:01" y:\!temp\Test4.jpg
And then upload it to google photos, it properly displays the correct time.
"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

DnvrMike

Phil:  1970 huh?  Well, that makes sense. The files prior to 1970 do get unpredictable results.  Makes sense now.
And yes, the date is not physical.  We are taking pictures of family photo albums going back to 1931 and we want them all to organize by date.  Funny thing is, the majority of photos work just fine using exiftool "-alldates<filename" .   May end up retaking the pix as possibly the exif is corrupted.  I do get errors sometimes.

StarGeek:  Picture is attached.

StarGeek

Quote from: DnvrMike on February 26, 2021, 10:26:15 PM
Phil:  1970 huh?  Well, that makes sense. The files prior to 1970 do get unpredictable results.

Here's where I last tested the limits of the Perl file system timestamp problems.  And the upper limit has advanced again. Exiftool cannot set the file system timestamps prior to 1972:01:01 00:00:00.  The lower limit has not changed.  Anything before 1899:12:31 23:59:59 will be set correctly.  But then, there isn't a file in existence that was created back then.

QuoteFunny thing is, the majority of photos work just fine using exiftool "-alldates<filename" .   May end up retaking the pix as possibly the exif is corrupted.

The problem only applies to the file system timestamps, FileCreateDate and FileModifyDate.  At least they do on Windows.  I actually don't know if there's a problem on Mac/Linux.

AllDates, as I said above, writes to the EXIF timestamps which are embedded in the file, not part of the underlying file system.  There's no problem with writing those as far back as you want.  I think I tried year 1 at one point and there wasn't a problem.
"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

StarGeek

I'm not sure why you're having a problem with that file.  I uploaded to Google Photos and it shows up properly with the 1936 date.

This is what shows up for me.  Am I not looking in the same place as you?
"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