Ignore time when using CreateDate<FileName

Started by eldo73, August 30, 2023, 07:54:43 AM

Previous topic - Next topic

eldo73

I have a directory of files named as such: 2011-2-2 MVI_0010 2.  I'd like to set the CreateDate Tag to the date found in the filename, but I get errors sometimes as it looks like exiftool is trying to interpret the 0010 2 portion as a time stamp.  It can work sometimes, I think by setting the time to 00:00:10 in this example, but it errors out when the number is >59.  Is there any way to just use the first 8 characters to set the date and ignore the rest?  Thanks in advance

StarGeek

Yes, the CreateDate requires a full date and time so you can't just provide the date.  You'll have to strip away the unwanted numbers and provide a dummy time.

Using the file name example you provided, you could strip away everything after "MVI" like this
exiftool "-CreateDate<${Filename;s/MVI.*$//i} 00:00:00" /path/to/files/

Example, here I use AllDates which includes the three most common EXIF timestamps, CreateDate, DateTimeOriginal, and ModifyDate.
C:\>exiftool -P -overwrite_original "-AllDates<${Filename;s/MVI.*$//i} 00:00:00" "Y:\!temp\aa\2011-2-2 MVI_0010 2.jpg"
    1 image files updated

C:\>exiftool -time:all --system:all -G -a -s "Y:\!temp\aa\2011-2-2 MVI_0010 2.jpg"
[EXIF]          ModifyDate                      : 2011:02:02 00:00:00
[EXIF]          DateTimeOriginal                : 2011:02:02 00:00:00
[EXIF]          CreateDate                      : 2011:02:02 00:00:00

Afterwords, you could increment the time with a second command like the one in this post.
* 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).

eldo73

Thank you for the quick reply.  I should have mentioned that I'm using zsh/OSX, and these are .MOV files.  Using the example%exiftool -P -overwrite_original "-AllDates<$(Filename;s/MVI.*$//i) 00:00:00" /Volumes/iMovie\ Data\ 4/Home\ Movies/2011/New\ Folder\ With\ Items/2011-1-13\ MVI_0049.MOV, I get the following output: zsh: command not found: Filename
zsh: no matches found: s/MVI.*$//i
Warning: No writable tags set from /Volumes/iMovie Data 4/Home Movies/2011/New Folder With Items/2011-1-13 MVI_0049.MOV
Warning: Invalid tag name '00:00:00'. Use '=' not '<' to assign a tag value - /Volumes/iMovie Data 4/Home Movies/2011/New Folder With Items/2011-1-13 MVI_0049.MOV
. Thanks again!

wywh

#3
If you are using Mac or Linux, use single quotes and try something like this for such filenames with only YYYY-MMDD like 2011-2-2 MVI_0099 2.mp4 (thanks to StarGeek how to crop the filename):

exiftool -overwrite_original -wm w -api QuickTimeUTC=1 -api LargeFileSupport=1 '-AllDates<${Filename;s/MVI.*$//i} 00:00:00' '-Track*Date<${Filename;s/MVI.*$//i} 00:00:00' '-Media*Date<${Filename;s/MVI.*$//i} 00:00:00' '-Keys:CreationDate<${Filename;s/MVI.*$//i} 00:00:00' '-FileCreateDate<${Filename;s/MVI.*$//i} 00:00:00' '-FileModifyDate<${Filename;s/MVI.*$//i} 00:00:00' .
In macOS the command asks for Xcode Command Line Tools install to modify file dates. That can be ignored but the install is quite small and fast, not the huge Xcode install.

BTW I have stubbornly used -overwrite_original_in_place to preserve some Mac metadata tags that the somewhat faster -overwrite_original deletes. But in macOS 13 also the latter preserves Finder color tags that are the only important such info for me so I might start using just -overwrite_original.

...and for a long time I have wondered why I must clumsily break the exiftool command with -execute to move FileCreateDate also forwards in time in the latter part of the command.

...well, I recently noticed that if I use -overwrite_original_in_place THEN also the FileCreateDate can move forwards in time.

Finder color tags survive -overwrite_original and also for XAttrMDItemWhereFroms -overwrite_original is enough. On the other hand, MDItemFSFinderFlags and MDItemFSLabel (the very last of the XAttrMDItemUserTags that some apps like GraphicConverter Browser use) need -overwrite_original_in_place to survive.

Use -api RequestAll=2 to see such MacOS info.

https://eclecticlight.co/2017/12/11/an-introduction-to-extended-attributes-xattrs/

https://eclecticlight.co/2017/12/19/xattr-com-apple-finderinfo-information-for-the-finder/

https://eclecticlight.co/2018/02/07/xattr-org-openmetainfo-and-org-openmetainfo-time-families-third-party-metadata/

https://eclecticlight.co/2023/06/22/what-to-do-when-spotlight-cant-find-it/

- Matti