Powershell escape problem - exiftool and "< " ?

Started by andy95, November 08, 2020, 07:23:17 AM

Previous topic - Next topic

andy95

Hello.


With "cmd" is this OK:
"exiftool.exe" -ext pdf -overwrite_original "-filename<${xmp:title;}.pdf" "c:\test\test.pdf"



With Powershell v5x (Win 10)
No error, but no function:
$i = "c:\test\test.pdf"
"& `"exiftool.exe`" -ext pdf -overwrite_original `"-filename`" `"<`" `"${xmp:title;}`" `"$i`""



$i = "c:\test\test.pdf"
"& `"exiftool.exe`" -ext pdf -overwrite_original `"-filename`" `"<`" `"${xmp:title;}.pdf`" `"$i`""
Error: File not found - .pdf


What is the problem with powershell and the source code?

Thanks for your help!

Luuk2005

#1
Greetings Andy.  This conducts well for me in the Powershell 5.1...
$i='PathToFilename.pdf'
& exiftool -ext pdf -overwrite_original -TESTname'<$Xmp:Title.%le' $i


You only need & if exiftool not inside %path%, so then to be like: & 'G:\PathTo\exiftool.exe' -ext pdf ...
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

andy95

Quote from: Luuk2005 on November 08, 2020, 09:39:14 AM
Thank's Luuk2005 for your help!

$i='PathToFilename.pdf'
& exiftool -ext pdf -overwrite_original -TESTname'<$Xmp:Title.%le' $i

I have tested several times: .%le file not found....

Please can you testing this:
PS Z:\test>

& c:\test\exiftool.exe -ext pdf -overwrite_original -TESTname'<$Xmp:Title.%le' Z:\test\a.pdf


Why this error?

Warning: [Minor] Ignored duplicate Info dictionary - Z:/test/a.pdf
'Z:/test/a.pdf' --> 'Z:/test/testtitle.pdf'
    0 image files updated
    1 image files unchanged



StarGeek

Quote from: andy95 on November 08, 2020, 11:55:13 AM
Why this error?

That's not an error, that's a warning.  It just means that there is some sort of error in the PDFs structure.

Also, test your command on the command line before putting it in a batch or script file to make sure it works.  If it works there, then the problem would have to be in the syntax of the batch or script.  Things to remember is that in PS, the dollar sign might be taken for a PS variable and the percent sign needs to be doubled in a batch file.
"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

Yes, please to listen everything that StarGeek is saying, and you can use -m so not to see the warnings anymore.
It seems that .pdf's can have both old and new Info dictionary... https://exiftool.org/forum/index.php?topic=4722.0
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

andy95

Luuk2005 and StarGeek!

Sorry, Sorry. But I have tested again and again - I found not the annoying problem.
Please test my attachmend:

This is my code with cmd:
"z:\exiftool.exe" -ext pdf -overwrite_original "-filename<${xmp:title;}.pdf" "Z:\test\old.pdf"
1 image files updated <- NO PROPLEM

The same code under powershell:
"& `"z:\exiftool.exe`" -ext pdf -overwrite_original `"-filename<`${xmp:title;}.pdf`" `"Z:\test\old.pdf`""

Powershell say:
PS Z:\test> "& `"z:\exiftool.exe`" -ext pdf -overwrite_original `"-filename<`${xmp:title;}.pdf`" `"Z:\test\old.pdf`""
& "z:\exiftool.exe" -ext pdf -overwrite_original "-filename<${xmp:title;}.pdf" "Z:\test\old.pdf"
PS Z:\test>


No function.

# ------

cmd:          "z:\exiftool.exe" -ext pdf -overwrite_original "-filename<${xmp:title;}.pdf" "Z:\test\old.pdf"
powershell: & "z:\exiftool.exe" -ext pdf -overwrite_original "-filename<${xmp:title;}.pdf" "Z:\test\old.pdf"


#-------

Please can anybody say the code for powershell because I have no more idea for a solution.



andy95

I found the solution:
& z:\exiftool.exe -ext pdf -overwrite_original -filename'<'` $"{xmp:title;}.pdf" Z:\test\old.pdf

powershell:


PS Z:\test> & z:\exiftool.exe -ext pdf -overwrite_original -filename'<'` $"{xmp:title;}.pdf" Z:\test\old.pdf
Warning: [Minor] Ignored duplicate Info dictionary - Z:/test/old.pdf
    1 image files updated
PS Z:\test>



Luuk2005

Geetings Andy!  There is many ways to do it, but why to always keep terminating single-quotes ??  This just makes you having to add more..
Also, you seem to like adding the double-quotes, and then backticks for to get literal-spaces ??

The easy way, like 1st example....................  -TESTname'<$Xmp:Title.%le'        (you post this working with -minor warning about .pdf file)
But if you really want more quotes.....,.........  -TESTname'<''$Xmp:Title.%le'      (two single-quotes after <)
To add literal-space, like in your solution.....  -TESTname'<'` '$Xmp:Title.%le'
If to be in love with quotes / literal-space..  -"TEST""name"'<'` ''"$"''"X"''"m"''"p"'':''"T"''"i"''"t"''"l"''"e"'.%le'

Maybe you try to create a 'quoting example' for someone else? but Im think the first example is to be much easier for teaching.
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

andy95

Quote from: Luuk2005 on November 09, 2020, 12:47:42 PM
There is many ways to do it, but why to always keep terminating single-quotes ??  This just makes you having to add more..
Also, you seem to like adding the double-quotes, and then backticks for to get literal-spaces ??
I have tested several times and it doesn't work without your escape idea.
There are no warnings from exiftool and powershell refuses to process them.

QuoteThe easy way, like 1st example....................  -TESTname'<$Xmp:Title.%le'        (you post this working with -minor warning about .pdf file)
This code:  -TESTname'<$Xmp:Title.%le' has no function! Powershell refuses!
No warning, nothing. And the pdf file have no update with exiftool.
I've made a few attempts with masking (escape) but all of the others didn't work and powershell except only my solution.

It is not of interest whether one or two more masks have to be set. It is important for me that the thing works.

Luuk2005

#9
Greetings Andy!  Sorry Im not say that -TESTname is only for expiraments, so it presents to your screen like..
'Z:/test/a.pdf' --> 'Z:/test/testtitle.pdf'  (but never conducts the rename)

So when to be happy with results, you must change -TESTname into -Filename
Many, many apologies if -TESTname was adding to the confusion!
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7