PowerShell Programming: Traverse folders and subfolders and apply pdftotext. I/O Error

Solution 1:

This NOT an answer but an extended comment following @FrankThomas. It would appear the following script "works"

$FOLDERS=@(Get-ChildItem -Path "C:\whiskey\Tango\Charlie" –Recurse)
$FOLDERS #print contents of array
foreach ($f in $FOLDERS) {
  & "C:\Program Files\xpdf-tools-win-4.02\bin32\pdftotext.exe" -enc UTF-8 $f.FullName
}

Indeed it goes through each folder and subfolder and executes the pdftotext program and so correctly extracts the contents of the pdf file into a text file. However I still have an error message: pdftotext.exe : I/O Error: Couldn't open file "C:\whiskey\Tango\Charlie". I suspect the name of every folder was saved in the array $FOLDERS. Subsequently PowerShell passes the name of the folder to pdftotext; which will error since it cannot find a .pdf extension.


The following is the correct PS script:

$FOLDERS=@(Get-ChildItem -Path "C:\whiskey\Tango\Charlie" –Recurse -Filter *.pdf)
$FOLDERS #print contents of every folder
foreach ($f in $FOLDERS) {
  & "C:\Program Files\xpdf-tools-win-4.02\bin32\pdftotext.exe" -enc UTF-8 $f.FullName
}

I need to filter for just pdf files.