Parse Filename to create Timesstamps, Creationdate

Started by chess, August 20, 2018, 02:17:57 PM

Previous topic - Next topic

chess

Hi,

I am trying to set my creationdate out if the Filename. I have the Year and Month in the filename, but not the day or the timestamps. I tried two ways, but unfortuntely both rrun into an error.

C:\Users\casuca\Documents\bb\exiftool "-datetimeoriginal=%%4.9f:%%2.14f:01 12:00:00" -overwrite_original .\Film_064_1991_10_Nokia_Masters_008.jpg

C:\Users\casuca\Documents\bb\exiftool "-datetimeoriginal=${filename;$_=substr($_,9,4)}:${filename;$_=substr($_,14,2)}:01 12:00:00" −overwrite_original .\Film_302_2000_10_Jever_Schwangerschaft_Carlotta__033.jpg

Any Idea how this can work?

Thanks

Carsten

StarGeek

In your first command, the %f notation only works with regards to writing to a filename, such as with the -w option or the Filename or Directory pseudo-tags.  You can't use it in a tag copy operation like this.

The problem with your second command is that you are using the equal sign =, Common Mistake #5c.  The equal sign is to assign a static value to the tag.  To copy a tag, you need to use the less/greater than signs </>

So if you change the equal sign to a less than sign in your second command, it should work.  But if you read FAQ #5, paragraph 3, you'll see don't need to format it exactly, just pull out the numbers you want.  So I'd probably try this:
exiftool "-datetimeoriginal<${filename;s/.*(\d{4}_\d\d).*/$1/} 01 12:00:00" −overwrite_original .\Film_302_2000_10_Jever_Schwangerschaft_Carlotta__033.jpg

It'll grab the pattern of 4 digits(Underscore)2 digits and remove everything else.  That will leave a string with a value of 2000_10 01 12:00:00 which exiftool will correctly parse into a time stamp of 2000:10:01 12:00:00  Note that you don't even need the spaces and colons.  If it was just 20001001120000, exiftool would parse it correctly.
"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

chess

Thanks StarGeek.

I tried it, but under Windows PowerShell it throws and error:

exiftool "-datetimeoriginal<${filename;s/.*(\d{4}_\d\d_) ...
+                                                                 ~
Use the Variable name `{ instead of {.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : OpenBraceNeedsToBeBackTickedInVariableName


Any Idea what to use "{4}" under Windows PowerShell


I also seen the construct "s/.*(\d{4}_\d\d).*/$1/". ANy hint for me where I can learn how the Notation works?


Thanks

Phil Harvey

Quote from: carsten.hess@vodafone.de on August 21, 2018, 03:58:12 PM
Any Idea what to use "{4}" under Windows PowerShell

I can't help here, but some googling for PowerShell escape may help.

QuoteI also seen the construct "s/.*(\d{4}_\d\d).*/$1/". ANy hint for me where I can learn how the Notation works?

See the last paragraph in StarGeek's post here.

- 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

Quote from: carsten.hess@vodafone.de on August 21, 2018, 03:58:12 PM
I tried it, but under Windows PowerShell it throws and error:

Try switching double quotes for single quotes.  Powershell seems to work more like bash when it comes to quotes.

I know some people swear by it, but Powershell is really crappy for use with exiftool.  For example, you can't stream binary data through file redirection or a pipe with it (see this post for details).  There was something else that was jaw droppingly stupid that PS did when using exiftool, but I can't remember what it was ATM.
"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