How to increment file creation date from file to file

Started by Arni, February 21, 2014, 10:38:49 AM

Previous topic - Next topic

Luuk2005

#45
Greetings Ceej, if there is not too many different dates, you can also try a batch like this...

@echo off
:: Its important all files to be in 1-folder with NO sub-folders
:: Set your FolderPath
cd /d "X:\Your\FolderPath"
:: Exit if finding any sub-folders
dir /b/ad . 2>nul |Findstr /r "^.">nul &&Exit
echo.
echo. Setting all times to 00:00:00
exiftool -overwrite_original -DateTimeOriginal"<${DateTimeOriginal;s/ .*//}000000" .
echo.
echo. Moving different-dates into sub-folders like yyyy-mm-dd
exiftool -overwrite_original -d "%%Y-%%m-%%d"  -Directory"<DateTimeOriginal" .
echo.
echo. Slowly incrementing times per sub-folder
:: This very slow because starts/stops for each folder!!
For /r %%A in (.) do @exiftool -overwrite_original -DateTimeOriginal+"<0:0:${FileSequence;$_*=10}" "%%A"
:: Move all sub-files back to parent
For /r %%A in (*.*) do @move "%%A" . 1>nul
:: Delete empty sub-folders
For /r %%A in (.) do rd "%%A" 2>nul
pause


Its to make your times in 10-second increments, but restarting at 00:00:00 for each new date.
But if there is many different dates, then this "bonus" part will probably not be worth waiting for!
This because StarGeek's one command creates the exact same order, but is so much faster (I just like the challenge for 'bonus').
It does also assume that your dates are inside $DateTimeOriginal.

*Edit: Added code to exit if finding any sub-folders, because what if someone else finds this, and does not follow advice?
Lol, at the end it moves all their files up one directory, and then deletes the empty folders!
 
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

StarGeek

Quote from: ceej on March 23, 2021, 07:42:52 PM
And I do not need to reset the time value whenever I start a new date (though that would be an added bonus).

I did miss this part.  I'm not sure how to do this without some scripting like Luuk2005's answer.

But instead of moving the files, using the HardLink tag from the Extra tags page to create a temporary directory structure would be better.   You can then delete the entire temp directory.

My edits to Luuk2005's batch file. This might require some tweaks with regards to the Temp directory setup, as I don't really do Windows batch files.  The idea I'm trying to set up is a directory called Temp in the same parent directory as the one being processed.
echo. Moving different-dates into sub-folders like yyyy-mm-dd
exiftool -overwrite_original -d "%%Y-%%m-%%d"  "-Directory<../Temp/$DateTimeOriginal/%%F" .
echo. Slowly incrementing times per sub-folder
:: This very slow because starts/stops for each folder!!
For /r %%A in (..\Temp\) do @exiftool -overwrite_original -DateTimeOriginal+"<0:0:${FileSequence}0" "%%A"
:: Delete empty sub-folders
del /S ..\Temp\
pause
"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

ceej

Wow!  I am awed at the quick and detailed responses.  I want to say a sincere thank you.
Below is the test program that I finally got to run (spent a LONG TIME before I discovered the need for ! instead of % inside the FOR loop).  And I tested with larger value of seconds to verify my supposition that it works.  I was only running a small batch of files, and getting  maybe 3 or 4 a second, so could live with that.  But I'll dive into the responses - now that I see that I can DO it, I hope to LEARN it.  (next effort will be to see if I can learn how to set fileCreateDate=exifCreateDate at the same time).
Again, my thanks.
  -ceej


echo off
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set /A seconds = 0
echo Start exiftool loop
for %%f in (*.jpg) do ( pause
set /A seconds = !seconds! + 10
echo FILE = %%f  SECONDS is !seconds!
rem Assign time increment
exiftool -CreateDate+="00:00:!seconds!" %%f
)
echo End of Program
pause
EXIT

ceej

Oh, and what is the difference between += and +<, particularly as it applies to my exiftool command, but also in general.
tx,
  -ceej

StarGeek

Quote from: ceej on March 24, 2021, 04:01:57 PM
Oh, and what is the difference between += and +<, particularly as it applies to my exiftool command, but also in general.

See Common Mistake #5c
"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

Luuk2005

Greetings everyone!
@StarGeek: Your improvement for a temp-folder is to be the best solution, but I cant edit the post anymore!????
Im thinking it can save people who like to remove the exit part, so then Im not getting blamed for all the trouble!
The improved batch does settle all conducted-files in a temp-folder, so then only conducted-files get moved back.

@Ceej: The latest For-Loop that you're now posting, does conduct exactly like StarGeek's one-command format...
exiftool -ext jpg -overwrite_original -CreateDate+"<0:0:${FileSequence;$_+=1;$_*=10}" "FolderPath"
Except the For-Loop is much slower, because its telling the exiftool to start/stop for each and every *.jpg
Also to quote %%f in case of names with spaces, and DelayedExpansion will not conduct the names with "!".
Both methods invented the same results, but this experiment presents the speed difference using 100 test-files...
     1-command:  0-min, 12-secs  (slow laptop)
     For-Loop:      6-min, 10-secs

Of course, the difference is to be much, much, greater with many hundreds or more of files!
I think of it like a train that goes really fast, but then having to start/stop for each jpg-passenger.
So at least make the passengers go to a folder, so then exiftool only has to stop at the folder stations.

Lol, instead of stopping and starting for each and every passenger waiting alongside at the rails.
Im also tested my batch for speed, but really that depends more on how many different-dates there can be?
The 100 test-files only had 4 different-dates, and the total time to get the "bonus" part was still 45-seconds.

So Im just guessing its probably about 10-seconds per different date, on a slow computer like mine. 
Also, it first resets the times to 00:00:00, because Im not sure if some files cannot already be like that?

If you like to experiment, you can change the begin-time from 10 to 00 by moving your set command under exiftool.
But of course, its still to be the same speed, and to give the same results as the one-command format...
exiftool -ext jpg -overwrite_original -CreateDate+"<0:0:${FileSequence}0" "FolderPath"

So if you like to experiment in the batch, its changing {FileSequence;$_+=1;$_*=10} <==> {FileSequence}0
Lol, never mind, I cant edit the batch, so its changing {FileSequence;$_+=1;$_*=10} <==> {FileSequence;$_*=10}

This was a hard part for me to understand, not realizing how long the start-up is, compared to the running speed.
Because with cmd-commands inside the For-Loop, you hardly even notice a difference, unless you're the Flash.
But for programs to look up 'libraries' and stuff, the difference is amazing, especially when looping them for each file.
There is something called "stay open", but I dont know how it works yet????
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

ceej

Once again, to all, thanks very much.  I finally "got" filesequence as a variable, much like the index of the FOR loop.  Head Slap!  Then so much made sense.  Also found additional (sub)pages in the documentation and was able to clear some more fog.  (Although the different names that are used for the same fields by various operating systems and programs is enough to drive one mad!).

Luuk2005 - thanks so much for your diving into the bonus!  Turns out I have many dates, and upon reflection, the need to restart at a new date was really not there.  However, I really appreciate your command for setting just the time value to 00:00:00 - and I even understood it.

Phil - thanks for the links to answers.  Although 'getting the answer' is quicker, the learning is less.  But I always appreciate being pointed to the page, at least.  So thanks again for your help as well as this awesome program.

Stargeek - ditto for your help.  When I understood how to have exiftool do what i wanted in just a single command, I fully grasped the time difference that it would take in a loop!

Below is what I ran, and the output that I got.
Can someone help with:
1. are these primarily exiftool 'fixing things' as it gathers data during its pass?
2. can I assume that warnings are just that - and I need not obsess on them?
3. It says 1 image file unchanged - but how do I know which?

and finally,
4. Just curious, is or can there be some problem with using DateTimeOriginal twice in this command:
exiftool -overwrite_original -fileOrder DateTimeOriginal "-DateTimeOriginal+<0:0:${filesequence}0" *.jpg

Thanks once again - all of what I wanted got done!
  -ceej


T:\Scanned_Images_Repository-1>exiftool -overwrite_original -DateTimeOriginal"<${DateTimeOriginal;s/ .*//}000000" *.jpg
Warning: [minor] Ignored empty rdf:Alt list for dc:description - 1960-12-15-P-004.jpg
Warning: [Minor] Can't handle XMP attribute 'xml:lang' - 1998-08-23-P-042.jpg
Warning: [Minor] Can't handle XMP attribute 'xml:lang' - 1999-08-25-P-009.jpg
Warning: [minor] Entries in IFD0 were out of sequence. Fixed. - F97-P-0039-1_edited-1.jpg
3751 image files updated

T:\Scanned_Images_Repository-1>exiftool -overwrite_original -fileOrder FileName "-DateTimeOriginal+<0:0:${filesequence}0" *.jpg
Warning: [Minor] Can't handle XMP attribute 'xml:lang' - 1998-08-23-P-042.jpg
Warning: [Minor] Can't handle XMP attribute 'xml:lang' - 1999-08-25-P-009.jpg
3750 image files updated
    1 image files unchanged

PS
It is so satisfying to open the directory in XNView and scroll down - watching the times creep up from midnight in 10-second increments!



StarGeek

Quote from: ceej on March 25, 2021, 10:14:26 PM
1. are these primarily exiftool 'fixing things' as it gathers data during its pass?

The minor warnings listed are probably not "fixed" except for the "Entries in IFD0 were out of sequence" as your command is most likely writing to EXIF tags and not the XMP tags where the warnings are popping up. Those might require adding the -m (-ignoreMinorErrors) option if you were to write to the XMP data to fix.  Odds are that none of those will prevent reading the data.

Quote2. can I assume that warnings are just that - and I need not obsess on them?

For the ones listed, yeah, no real need to obsess over them.  But if you wanted you could try running the command listed in FAQ #20 to re-write all the metadata.  Though if you have some unusual metadata that exiftool doesn't know about (sorta rare), that could be lost. 

Quote3. It says 1 image file unchanged - but how do I know which?

It's the first one.  FileSequence starts at 0, so the first file processed would add 0 seconds, which would be unchanged from the original value.

Quote4. Just curious, is or can there be some problem with using DateTimeOriginal twice in this command:
exiftool -overwrite_original -fileOrder DateTimeOriginal "-DateTimeOriginal+<0:0:${filesequence}0" *.jpg

No.  The first occurrence is the second argument of the -FileOrder option.  It tells exiftool to make a pass over all the files to extract the DateTimeOriginal value for each file, sort all the files by that tag, and process them in that order.  It might be unnecessary, depending upon the file names, as it will take a bit longer because it has to pass over all the files to get the data first and then run again to actually process the files.  It's up to you to decide if it might be needed.  For me, using it is a requirement in situations like this because I use Stablebit DrivePool and the file list passed to exiftool is not alphabetized like it would be for a non-pooled drive.
"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

oivindmi

Quote from: Phil Harvey on February 21, 2014, 10:53:28 AM
Hi Arni,

This is a bit tricky, but you could do this with 2 commands:

1) First set all images to the same date/time:

exiftool -datetimeoriginal="2014:02:21 10:48:00" DIR

2) Increment the times by one additional minute for each file:

exiftool '-datetimeoriginal+<0:$filesequence' DIR

where DIR is a directory containing the images.  (You must use single quotes instead of double quotes around the argument in the second command since you are running on a Mac.) The +< syntax copies the value of other tags and uses it to increment the target tag, and the format for incrementing minutes is "0:MM".  Here, I have used the Extra FileSequence tag to give me the incrementing values that we need.

On a Mac, the files will be processed in alphabetical order, so you don't need to worry about this.  (ie. specifying -fileorder FileName should not be necessary.)

- Phil

Hope it is okay to post here. I want to increment a folder of pictures by 1 sec in windows. I am getting the following command to work but I seem to have issues with the sequence Exiftool is processing pictures:

Command: exiftool "-AllDates+<0:0:$filesequence" "folder"  -overwrite_original -r

Sequence that Exiftool seems to be processing the files:
Picture (1)
Picture (10)
Picture (11)
Picture (2)
Picture (3)
Picture (4)
Picture (5)
Picture (6)
Picture (7)
Picture (8)
Picture (9)

I would really like Exiftool to process the files according to the numbering 1,2,3,4,5,6,7,8,9,10,11. This is standard renaming scheme in Windows. Is there a way for Exiftool to follow this sequence?




StarGeek

Not really.  Exiftool will process the files as the list is delivered to it by the file system.  This is normally as if they were sorted strings which don't take into account the value of the numbers.

Your best bet is to either rename them with leading zeros or you can extract the number from the filename and add that instead of using filesequence
exiftool "-AllDates+<0:0:${Filename;m/\((\d+)\)/;$_=$1}" -overwrite_original -r /path/to/files/
"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

oivindmi

Thank you very much for your informative and quick reply! Very much appreciated! I think I can definetely work with this :)

One quick question, is it possible to add a multiple on this formula? So that the extracted number of seconds is multiplied by a given number? (3 or 5 or7 etc.)

Also, if I want to understand how your formula is built up, what is the best resource to understand what each command does? I have a rudimentary understanding of Exiftool commands, but always get lost when the commands get as complicated as your example.

StarGeek

Quote from: oivindmi on October 05, 2021, 04:24:29 AM
One quick question, is it possible to add a multiple on this formula? So that the extracted number of seconds is multiplied by a given number? (3 or 5 or7 etc.)

Yes.  I'm a little surprised it didn't pop up in this thread earlier but it get's mentioned in the comments on this Photo StackExchange post.  For example, this would add 3 seconds per increment.
exiftool "-AllDates+<0:0:${filesequence;$_*=3}" /path/to/files/

If you use the above Filename based command, you would change the $_=$1 part to $_=$1;$_*=3 or even $_=$1*3.

QuoteAlso, if I want to understand how your formula is built up, what is the best resource to understand what each command does?

The advanced formatting uses Perl code so some basic knowledge of Perl is helpful. There are lots of tutorial sites out there. When I was learning, I usually Googled what I wanted to try and do and added "Perl" in quotes to the search.  This often brought up code snippets from sites like StackOverflow/StackExchange that I was able to use after much trial and error.
"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