Author Topic: Increment datetime by 5 using FileSequence extra tag & file renaming  (Read 2042 times)

beacon

  • Newbie
  • *
  • Posts: 3
Hi,

I recently upload a bunch of pictures as tif files from many years ago. I know the date and the approximate time range when the pictures were taken and trying to modify the date/time and file name based on the range (between 7:00 PM and 10:00 PM on the date in question). The pictures were taken with an old disposable camera and I was given duplicates, so there's an a.tif and b.tif version of each file in the same folder. I'm perfectly content moving the b.tif versions to another folder for processing, but it would be cool if there's a way to accomplish what I'm trying to do. With that in mind, I have two questions that will help me figure out if what I'm trying to do is possible:

1. I've seen a couple of posts that indicate that the FileSequence extra tag can be used to increment a datetime value after the datetime has initially been set to the same datetime. However, most of the examples use FileSequence to increment values by 1 minute (+<0:$filesequence) or by 10 minutes (+<0:${filesequence}0). I found one example where the datetime values were being incremented by 3 (${filesequence:$_*=3}), but I'm assuming this is a Perl implementation as I have been unable to get this to work in PowerShell even if I escape the $ character. So, is it possible to use the ${filesequence:$_*=5} code in PowerShell to increment the dates by a value other than 1 or 10? Here's the example I found:

exiftool "-datetimeoriginal+<0:0:${filesequence;$_*=3}" DIR

2. If the file name, before modifying AllDates is something like "19750101_010000-New Years 001a.tif" (and "19750101_010000-New Years 001b.tif" for the duplicate), is there a way, after modifying the dates using some method similar to the above, to rename the file in the same format? In other words, if the file name is "19750101_010000-New Years 030a.tif", the file name would need to be changed to something closer to "19750101_032500-New Years 030a.tif", which is 2 hours and 25 minutes offset from the first picture taken. I've read up on and feel comfortable changing/formatting the datetime as a string, but I'm not sure if I can parse the datetime that's already attached to the file name to use the new datetime while keeping the "-New Years 030a.tif".

Thanks.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3146
Re: Increment datetime by 5 using FileSequence extra tag & file renaming
« Reply #1 on: September 20, 2016, 09:14:51 PM »
1. I've seen a couple of posts that indicate that the FileSequence extra tag can be used to increment a datetime value after the datetime has initially been set to the same datetime. However, most of the examples use FileSequence to increment values by 1 minute (+<0:$filesequence) or by 10 minutes (+<0:${filesequence}0). I found one example where the datetime values were being incremented by 3 (${filesequence:$_*=3}), but I'm assuming this is a Perl implementation

It works with the executable.  The problem is you're using colons : where you should be using semicolons ;.  Use colons when it's part of the timestamp, semicolon when it's between the braces.  So here's the command you'd want to use:
exiftool "-datetimeoriginal+<0:0:${filesequence;$_*=5}" DIR

Code: [Select]
c:\>exiftool -datetimeoriginal X:\!temp\Test3*
======== X:/!temp/Test3.jpg
Date/Time Original              : 2015:09:10 00:00:00
======== X:/!temp/Test3a.jpg
Date/Time Original              : 2015:09:10 00:00:00
    2 image files read

c:\>exiftool -P -overwrite_original  "-datetimeoriginal+<0:0:${filesequence;$_*=5}" X:\!temp\Test3*
    1 image files updated
    1 image files unchanged

c:\>exiftool -datetimeoriginal X:\!temp\Test3*
======== X:/!temp/Test3.jpg
Date/Time Original              : 2015:09:10 00:00:00
======== X:/!temp/Test3a.jpg
Date/Time Original              : 2015:09:10 00:00:05
    2 image files read

One thing to take note of is that filesequence starts a 0, so the first file isn't incremented.  If you wish to start at a different number, you need to increment it before the multiplication with this $_+=StartingNumber; where you replace StartingNumber with the number you want to start with.  For example, to start with 4, the filesequence part would look like this:
${filesequence;$_+=4;$_*=5}

For the second part, try something like this:
exiftool -d "%Y%m%d_%H%M%S" "-filename<${DateTimeOriginal}${filename;s/^\d{8}_\d{6}//}" DIR

Code: [Select]
c:\>exiftool -datetimeoriginal X:\!temp\y
======== X:/!temp/y/19750101_010000-New Years 001a.jpg
Date/Time Original              : 1975:01:01 01:00:00
======== X:/!temp/y/19750101_010000-New Years 002a.jpg
Date/Time Original              : 1975:01:01 01:00:00
    1 directories scanned
    2 image files read

c:\>exiftool -P -overwrite_original "-datetimeoriginal+<0:0:${filesequence;$_*=5}" X:\!temp\y
    1 directories scanned
    1 image files updated
    1 image files unchanged

c:\>exiftool -datetimeoriginal X:\!temp\y
======== X:/!temp/y/19750101_010000-New Years 001a.jpg
Date/Time Original              : 1975:01:01 01:00:00
======== X:/!temp/y/19750101_010000-New Years 002a.jpg
Date/Time Original              : 1975:01:01 01:00:05
    1 directories scanned
    2 image files read

c:\>exiftool -d "%Y%m%d_%H%M%S" "-filename<${DateTimeOriginal}${filename;s/^\d{8}_\d{6}//}" X:\!temp\y
    1 directories scanned
    1 image files updated
    1 image files unchanged

c:\>exiftool -datetimeoriginal X:\!temp\y
======== X:/!temp/y/19750101_010000-New Years 001a.jpg
Date/Time Original              : 1975:01:01 01:00:00
======== X:/!temp/y/19750101_010005-New Years 002a.jpg
Date/Time Original              : 1975:01:01 01:00:05
    1 directories scanned
    2 image files read
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.

beacon

  • Newbie
  • *
  • Posts: 3
Re: Increment datetime by 5 using FileSequence extra tag & file renaming
« Reply #2 on: September 20, 2016, 11:35:29 PM »
Hi StarGeek,

I had a typo in my post, but I was using the semi-colon in my script. I believe that part of the problem had to do with my quoting and escaping characters. That being said, I'm still having trouble with the first part. Here's my latest attempt at the code, in PowerShell:

Code: [Select]
$cmd_rev = '& C:\exiftool\exiftool.exe -v "-AllDates+<0:${filesequence;$_*=3}" "C:\1975-01-01 New Years" -FileOrder FileName -overwrite_original -r > C:\ExifOutput.txt'
Invoke-Expression $cmd_rev

Prior to running the above code, I run code to set the AllDates tag to "1975:01:01 01:00:00" and that worked perfectly. I used exiftool -s -a DIR to output the results and every file had the new tags created with the aforementioned date assigned.

When I run the code I provided above, I get errors indicating Warning: No writable tags set from [file] and Warning: Invalid tag name '0:'. After the first error, I received the additional info At line:1 char:1
+ & C:\exiftool\exiftool.exe -v "-AllDates+<0:${filesequence;$_*=3}" "C ...
.

I have written and re-written the script to escape and quote this bit of code every way I can think of, to no avail. I feel like I'm missing something simple, but I'm not seeing it and the error messages aren't clear since I confirmed that the tags created by AllDates are available for every file.

Thanks.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3146
Re: Increment datetime by 5 using FileSequence extra tag & file renaming
« Reply #3 on: September 21, 2016, 05:36:15 PM »
I don't know that much about power shell, but I was able to get this to work:

Code: [Select]
$cmd_rev = 'exiftool.exe  "-AllDates+<0:`${filesequence;`$_*=3}" "X:\!temp\y" -FileOrder FileName -overwrite_original -r '
Invoke-Expression $cmd_rev

Your errors seem to be powershell errors, which are outside of my knowledge.
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.