Author Topic: Process images only if FileModifyDate not equals FileName  (Read 416 times)

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Process images only if FileModifyDate not equals FileName
« on: February 23, 2019, 09:58:43 PM »
Hello.

I'm trying to change the FileModifyDate based in the FileName, but only if they are different. But my code is not working...  ::)

For example, this 8 files already have the FileName synchronized to the FileModifyDate
Code: [Select]
$ ls -lT
total 134078
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 2009-04-25 14.13.36-1.avi
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 2009-04-25 14.13.36.avi
-rw-r--r-- 1 user  group  15346696  2 oct 12:37:19 2010 2010-10-02 12.37.19.dng
-rw-r--r-- 1 user  group  27328928 16 oct 12:44:02 2010 2010-10-16 12.44.02.dng
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32-1.nef
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32.nef
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19-1.jpg
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19.jpg

But this code is not working as expected (that is, only change FileModifyDate if it's different to FileName):

Code: [Select]
$ exiftool -ext '*' '-FileModifyDate<FileName' -if '$FileModifyDate ne $FileName' .
Warning: [minor] Bad IDC_IFD SubDirectory start - ./2010-10-16 12.44.02.dng
    1 directories scanned
    8 image files updated


Ah, one more question please, if I don't expecify -ext '*' then the avi file is not processed, why?
Code: [Select]
$ exiftool '-FileModifyDate<FileName' -if '$FileModifyDate ne $FileName' .
Warning: [minor] Bad IDC_IFD SubDirectory start - ./2010-10-16 12.44.02.dng
    1 directories scanned
    6 image files updated


This is using macOS.

Thank you very much in advance!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Process images only if FileModifyDate not equals FileName
« Reply #1 on: February 23, 2019, 10:31:41 PM »
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 2009-04-25 14.13.36-1.avi

File names like this will always be not equal to a date/time because they aren't formatted the same way (plus they have an extension).  I can show you how to do this, but it will be a bit complex and I don't have time at the moment.  I'll try to do this tomorrow.


Quote
Ah, one more question please, if I don't expecify -ext '*' then the avi file is not processed, why?

This is FAQ 16.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2368
Re: Process images only if FileModifyDate not equals FileName
« Reply #2 on: February 23, 2019, 10:53:19 PM »
Code: [Select]
$ exiftool -ext '*' '-FileModifyDate<FileName' -if '$FileModifyDate ne $FileName' .
Warning: [minor] Bad IDC_IFD SubDirectory start - ./2010-10-16 12.44.02.dng
    1 directories scanned
    8 image files updated

ne will return true if the two things being compared are not equal.  Exiftool will return a date in the format of YYYY:MM:DD HH:mm:ss.  Unless the file name exactly matches that, it will always not be equal.  You're comparing 2009:04:25 14:13:36 to 2009-04-25 14.13.36-1.avi, obviously not equal.  What you want to do is format the numbers in the filename to the same as what is returned from FileModifyDate, or something along those lines.

Try this.  I haven't tested it but it might do what you want.
exiftool -ext '*' '-FileModifyDate<FileName' -if '${FileModifyDate;tr/0-9//cd} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .

The tr/0-9//cd sets up a translate function.  It creates a set of all digits 0-9, complements the set (the c option) so that it matches anything not a digit, and then deletes them (the d option).  Thus, you're left with nothing but numbers.   For the filename, there's a follow up that drops any numbers after the first 14. So, for example, file 2009-04-25 14.13.36-1.avi would end up comparing "20090425141336" to "20090425141336" (having dropped the trailing "1"). 
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #3 on: February 23, 2019, 11:12:26 PM »
Thank you very much to both!

And sorry Phil for not reading the FAQ before   ;D


@StarGeek: Brilliant! What you propose should work, but unfortunately:

Code: [Select]
$ exiftool -ext '*' '-FileModifyDate<FileName' -if '${FileModifyDate;tr/0-9//cd} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .
Warning: [minor] Bad IDC_IFD SubDirectory start - /mnt/zfast/Users/vicmarto/Pictures/[P]/2010-10-16 12.44.02.dng
    1 directories scanned
    8 image files updated

$ ls -lT
total 134078
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 2009-04-25 14.13.36-1.avi
-rw-r--r-- 1 user  group    304216 25 abr 14:13:36 2009 2009-04-25 14.13.36.avi
-rw-r--r-- 1 user  group  15346696  2 oct 12:37:19 2010 2010-10-02 12.37.19.dng
-rw-r--r-- 1 user  group  27328928 16 oct 12:44:02 2010 2010-10-16 12.44.02.dng
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32-1.nef
-rw-r--r-- 1 user  group  11003879 14 ene 17:45:32 2018 2018-01-14 17.45.32.nef
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19-1.jpg
-rw-r--r-- 1 user  group   1676995 20 feb 22:13:19 2019 2019-02-20 22.13.19.jpg
« Last Edit: February 23, 2019, 11:23:02 PM by vicmarto »

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2368
Re: Process images only if FileModifyDate not equals FileName
« Reply #4 on: February 24, 2019, 12:43:39 AM »
What is the output of
exiftool -ext '*' -p '${FileModifyDate;tr/0-9//cd} ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #5 on: February 24, 2019, 12:54:16 AM »
Thanks StarGeek for your help:

Code: [Select]
$ exiftool -ext '*' -p '${FileModifyDate;tr/0-9//cd} ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .
200904251413360900 20090425141336
201010021237190900 20101002123719
201902202213190900 20190220221319
201010161244020900 20101016124402
Warning: Bad IDC_IFD SubDirectory start - ./2010-10-16 12.44.02.dng
201801141745320900 20180114174532
200212272214320900 20021227221432
200904251413360900 20090425141336
201801141745320900 20180114174532
201902202213190900 20190220221319

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2368
Re: Process images only if FileModifyDate not equals FileName
« Reply #6 on: February 24, 2019, 01:06:12 AM »
Hmm…  A trailing 0900 in each of the FileModifyDate tags.  I don't know enough about Mac to know why but the solution is the same as removing extra trailing numbers from the filename

Try
exiftool -ext '*' '-FileModifyDate<FileName' -if '${FileModifyDate;tr/0-9//cd;s/^(\d{14}).*/$1/} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .

Phil might be able to come up with something better tomorrow.  Sorry, I'll be heading to bed in a few minutes.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #7 on: February 24, 2019, 01:17:07 AM »
Thanks StarGeek!! This worked perfectly.

And yes, I'm agree, macOS sometimes do odd things  ;D

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Process images only if FileModifyDate not equals FileName
« Reply #8 on: February 24, 2019, 07:41:48 AM »
The trailing digits in FileModifyDate where the time zone.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2368
Re: Process images only if FileModifyDate not equals FileName
« Reply #9 on: February 24, 2019, 12:18:37 PM »
The trailing digits in FileModifyDate where the time zone.

And there's my Homer D'oh moment of the day.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #10 on: February 25, 2019, 08:30:07 PM »
The trailing digits in FileModifyDate where the time zone.

And there's my Homer D'oh moment of the day.

Hahhahaa, yes! Me too. Thanks to both! Really!  ;D

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #11 on: February 27, 2019, 09:39:16 AM »
Hmm…  A trailing 0900 in each of the FileModifyDate tags.  I don't know enough about Mac to know why but the solution is the same as removing extra trailing numbers from the filename

Try
exiftool -ext '*' '-FileModifyDate<FileName' -if '${FileModifyDate;tr/0-9//cd;s/^(\d{14}).*/$1/} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' .

Phil might be able to come up with something better tomorrow.  Sorry, I'll be heading to bed in a few minutes.

Arrrrgggghhh!! Sorry StarGeek, can't understand why... Your code was working perfectly when integrated in my ExifTool order, this one:
Code: [Select]
exiftool \
-d '%Y-%m-%d %H.%M.%S' -ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' -IPTC:all= -XMP:all= -Photoshop:all= \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}%-c.${FileTypeExtension}' \
'-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
'-FileName<${ModifyDate}.${SubSecTime;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
'-FileName<${CreateDate}.${SubSecTimeDigitized;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
'-FileName<${DateTimeOriginal}.${SubSecTimeOriginal;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
-execute \
-d '%Y-%m-%d %H.%M.%S' -ext 'png' -IPTC:all= -XMP:all= -Photoshop:all= \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${DateCreated}%-c.${FileTypeExtension}' \
-execute \
-d '%Y-%m-%d %H.%M.%S' -ext 'avi' \
-api largefilesupport=1 '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
-execute \
-d '%Y-%m-%d %H.%M.%S' -ext 'mov' -ext 'mp4' \
-api largefilesupport=1 '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${CreationDate}%-c.${FileTypeExtension}' \
-execute \
-ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' -ext 'png' -ext 'avi' -ext 'mov' -ext 'mp4' \
-if '${FileModifyDate;tr/0-9//cd;s/^(\d{14}).*/$1/} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' '-FileModifyDate<FileName' \
-common_args -r -overwrite_original \
.

BUT, when I hardcore the desired output directory into the -d option (to make a shell script) instead of ., don't work anymore! The files do not get the correct FileModifyDate!!!:
Code: [Select]
exiftool \
-d '/Users/user/Pictures/%Y-%m-%d %H.%M.%S' -ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' -IPTC:all= -XMP:all= -Photoshop:all= \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}%-c.${FileTypeExtension}' \
'-FileName<${ModifyDate}%-c.${FileTypeExtension}' '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
'-FileName<${ModifyDate}.${SubSecTime;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
'-FileName<${CreateDate}.${SubSecTimeDigitized;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
'-FileName<${DateTimeOriginal}.${SubSecTimeOriginal;$_=substr($_.'0',0,2)}.${FileTypeExtension}' \
-execute \
-d '/Users/user/Pictures/Screenshots/%Y-%m-%d %H.%M.%S' -ext 'png' -IPTC:all= -XMP:all= -Photoshop:all= \
'-FileName<${FileModifyDate}%-c.${FileTypeExtension}' '-FileName<${MetadataDate}%-c.${FileTypeExtension}' '-FileName<${DateCreated}%-c.${FileTypeExtension}' \
-execute \
-d '/Users/user/Pictures/%Y-%m-%d %H.%M.%S' -ext 'avi' \
-api largefilesupport=1 '-FileName<${DateTimeOriginal}%-c.${FileTypeExtension}' \
-execute \
-d '/Users/user/Pictures/%Y-%m-%d %H.%M.%S' -ext 'mov' -ext 'mp4' \
-api largefilesupport=1 '-FileName<${CreateDate}%-c.${FileTypeExtension}' '-FileName<${CreationDate}%-c.${FileTypeExtension}' \
-execute \
-ext 'arw' -ext 'dng' -ext 'jpg' -ext 'jpeg' -ext 'nef' -ext 'tif' -ext 'tiff' -ext 'png' -ext 'avi' -ext 'mov' -ext 'mp4' \
-if '${FileModifyDate;tr/0-9//cd;s/^(\d{14}).*/$1/} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' '-FileModifyDate<FileName' \
-common_args -r -overwrite_original \
.

All is the same except the -d option. Please, help... Thanks!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Process images only if FileModifyDate not equals FileName
« Reply #12 on: February 27, 2019, 09:46:59 AM »
Do you mean that the files moved to that directory have the wrong FileModifyDate.  I'm assuming that the file name is correct.  If you move a file to a different filesystem then the FileModifyDate will change unless you add -P to the command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #13 on: February 27, 2019, 09:57:03 AM »
Yes, I know, but in this case and thank to the code from StarGeek:

-if '${FileModifyDate;tr/0-9//cd;s/^(\d{14}).*/$1/} ne ${FileName;tr/0-9//cd;s/^(\d{14}).*/$1/}' '-FileModifyDate<FileName'

The file must sync its FileModifyDate with it's FileName (instead of the original FileModifyDate, because now the FileModifyDate of my photos is a totally mess!)


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Process images only if FileModifyDate not equals FileName
« Reply #14 on: February 27, 2019, 10:03:14 AM »
I'm afraid that I'm a bit lost here.  When you say the FileModifyDate of your photos is a total mess, can you give an example for one file?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #15 on: February 27, 2019, 10:05:01 AM »
I'm afraid that I'm a bit lost here.  When you say the FileModifyDate of your photos is a total mess, can you give an example for one file?

- Phil

This one, for example:

$ exiftool -s -time:all -a -G0:1 2002-12-27\ 22.14.32-1.jpg
[File:System]   FileModifyDate                  : 1990:01:01 00:00:00+09:00
[File:System]   FileAccessDate                  : 1990:01:01 00:00:00+09:00
[File:System]   FileInodeChangeDate             : 1990:01:01 00:00:00+09:00
[EXIF:IFD0]     ModifyDate                      : 2002:12:27 22:14:32
[EXIF:ExifIFD]  DateTimeOriginal                : 2002:12:27 22:14:32
[FlashPix]      ExtensionCreateDate             : 0
[FlashPix]      ExtensionModifyDate             : 0

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14425
    • ExifTool Home Page
Re: Process images only if FileModifyDate not equals FileName
« Reply #16 on: February 27, 2019, 10:20:31 AM »
Ah.  The problem is that your last command needs to set the FileModifyDate for files in the destination directory, not the source directory.  So you can't use "." as a directory name in the command with -if either.  See my other post when I move this out of the -common_args, and change the "." for this command only.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

vicmarto

  • Jr. Member
  • **
  • Posts: 27
Re: Process images only if FileModifyDate not equals FileName
« Reply #17 on: February 28, 2019, 06:06:43 AM »
Thanks Phil, let's continue in the other topic, now they are related.