Powershell problem with "-DateTimeOriginal<${Filename;m/^(\d{4}-\d\d)/;$_=$1} 01

Started by robertklink, January 19, 2022, 02:40:40 PM

Previous topic - Next topic

robertklink

Windows environment.

Working on a Powershell script to merge together what is currently a series of CMD window eixftool actions and Powershell script actions. All of which work fine alone in their respective environments.

Specific problem is taking this CMD action:
exiftool -P "-DateTimeOriginal<${Filename;m/^(\d{4}-\d\d)/;$_=$1} 01 12:00:00" .

and putting into Powershell

This action is intended to operate on filenames of format YYYY-MM-ROLL_ID-NEGATIVE# to take the YYYY-MM from the filename, add a dummy DD HH:MM:SS to it and write it to DateTimeOriginal.

For troubleshooting I'm running just that one command in Powershell 7, with some syntax tweaks between runs. Results are as follows:

PS C:\Users\rober> exiftool -P "-DateTimeOriginal<${Filename;m/^(\d'{4}-\d\d)/;$_=$1} 01 12:00:00" "C:\Users\rober\Pictures\Date and Incr SANDBOX\1997\1997-06-P306-00.JPG"
ParserError:
Line |
   1 |  exiftool -P "-DateTimeOriginal<${Filename;m/^(\d'{4}-\d\d)/;$_=$1} 01 ...
     |                                                    ~
     | Use `{ instead of { in variable names.

PS C:\Users\rober> exiftool -P "-DateTimeOriginal<${Filename;m/^(\d'{4}'-\d\d)/;$_=$1} 01 12:00:00" "C:\Users\rober\Pictures\Date and Incr SANDBOX\1997\1997-06-P306-00.JPG"
ParserError:
Line |
   1 |  exiftool -P "-DateTimeOriginal<${Filename;m/^(\d'{4}'-\d\d)/;$_=$1} 0 ...
     |                                                    ~
     | Use `{ instead of { in variable names.

PS C:\Users\rober> exiftool -P "-DateTimeOriginal<$'{Filename;m/^(\d'{4}'-\d\d)/;$_=$1} 01 12:00:00" "C:\Users\rober\Pictures\Date and Incr SANDBOX\1997\1997-06-P306-00.JPG"
Warning: [minor] Unrecognized MakerNotes - C:/Users/rober/Pictures/Date and Incr SANDBOX/1997/1997-06-P306-00.JPG
Warning: No writable tags set from C:/Users/rober/Pictures/Date and Incr SANDBOX/1997/1997-06-P306-00.JPG
    0 image files updated
    1 image files unchanged
PS C:\Users\rober> exiftool -P "-DateTimeOriginal<$'{Filename;m/^(\d'{4}-\d\d)/;$_=$1} 01 12:00:00" "C:\Users\rober\Pictures\Date and Incr SANDBOX\1997\1997-06-P306-00.JPG"
Warning: [minor] Unrecognized MakerNotes - C:/Users/rober/Pictures/Date and Incr SANDBOX/1997/1997-06-P306-00.JPG
Warning: No writable tags set from C:/Users/rober/Pictures/Date and Incr SANDBOX/1997/1997-06-P306-00.JPG
    0 image files updated
    1 image files unchanged
PS C:\Users\rober>


Attachment is an actual screen grab of above showing the PS7 color coding.

The first 3 tries had parser errors that I solved by replacing { with '{

The last two tries did not function in exiftool. I believe that the problem relates to $ signs. Probably need some escape syntax added, but I'm at a loss as what specifically . Hence posting on Exiftool forum rather than PS forum.

Same problem in "regular" PS and PSE ISE.

StarGeek

You'll want to use single quotes with Powershell otherwise the dollar sign is interpreted as a shell variable. 

Try
exiftool -P '-DateTimeOriginal<${Filename;m/^(\d{4}-\d\d)/;$_=$1} 01 12:00:00' .
* 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).

robertklink

Yup that worked. And it's simple enough I might even remember it.

Was able to apply it to other commands in my full script and get that working.

Thanks

Bob_K

Non-technical comment:

Usernames "robertklink" and "Bob_K" are actually the same person (me).
I'm not sure how I stumbled into that happening.
My password manager only has "Bob_K" info stored in it.
"Bob_K" is my preferred username / the one I intend to keep using.