Monday, 13 August 2018

windows 10 - PowerShell Unexpected Token Error



Question: I am running the following script in Windows 10 via the PowerShell ISE



cd C:\Users\xyz\Desktop\pdfs
$FILES= ls *.pdf
foreach ($f in $FILES) {
"C:\Program Files\xpdf-tools-win-4.01.01\bin32\pdftotext.exe" -enc UTF-8 "$f"
}


I am receiving the following errors



  • unexpected token 'enc' in expression or statement

  • unexpected token 'UTF-8' in expression or statement


How do I correct those error ?





I suspect, although I am by no means certain, the error is due to incorrect " or ' marks. I have attempted the following change


cd C:\Users\xyz\Desktop\pdfs
$FILES= ls *.pdf
foreach ($f in $FILES) {
"C:\Program Files\xpdf-tools-win-4.01.01\bin32\pdftotext.exe -enc UTF-8 $f"
}

; which surprisingly executes but fails to generate any text files and I am expecting those files to be found in the folder ...\pdfs.


Reference



Answer




Solution: I was missing an ampersand, &. A deeper search on Stack Overflow turned up this question; which provided me with the correction. Very fast, and much faster than anything native in Adobe Acrobat DC !



cd C:\Users\xyz\Desktop\pdfs
$FILES= ls *.pdf
foreach ($f in $FILES) {
& "C:\Program Files\xpdf-tools-win-4.01.01\bin32\pdftotext.exe" -enc UTF-8 "$f"
}

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...