Page 1 of 1

how to read file name with spaces?

Posted: 09 Feb 2018 14:42
by lalat06bag
Below code is to convert all pdf files to txt.

Code: Select all

@echo off &setlocal
set "pdfToText=C:\Users\u595142\Desktop\xpdf32\pdftotext.exe" & rem source for the pdftotext exe
set "allPdfFiles=C:\Users\u595142\Desktop\allPdfFiles" & rem source pdf folder
set "allTxtFiles=C:\Users\u595142\Desktop\allTxtFiles" & rem source txt folder
if not exist "%allTxtFiles%" mkdir "%allTxtFiles%"

for /f %%v in ('dir /b %allPdfFiles%\*.pdf') do (
  "%pdfToText%" "%allPdfFiles%\%%v" "%allTxtFiles%\%%~nv.txt" >NUL 2>&1 || echo Error converting %%v
)

endlocal
exit/B
It could not read the filenames with space.
If fine name is XXXX_QRRPS Tran book - 0utgoing-en-in_2018-02-09T024757245Z.pdf, it reads XXXX_QRRPS.
can any one please see?

Re: how to read file name with spaces?

Posted: 09 Feb 2018 15:32
by Squashman
Turn ECHO ON at the top of your script and show us all the console output processing that one specific file.

Re: how to read file name with spaces?

Posted: 09 Feb 2018 15:54
by lalat06bag
Please see now.

for /f %%v in ('dir /b %allPdfFiles%\*.pdf') do (
"%pdfToText%" "%allPdfFiles%\%%v" "%allTxtFiles%\%%~nv.txt" >NUL 2>&1 || echo Error converting %%v
echo %pdfToText%
echo %allPdfFiles%\%%v
echo %allTxtFiles%\%%~nv.txt
pause
)

Error converting XXXX_QRRPS
C:\Users\u595142\Desktop\xpdf32\pdftotext.exe
C:\Users\u595142\Desktop\allPdfFiles\XXXX_QRRPS
C:\Users\u595142\Desktop\allPdfFiles\XXXX_QRRPS.txt
Press any key to continue

Re: how to read file name with spaces?

Posted: 09 Feb 2018 16:18
by Squashman
lalat06bag wrote:
09 Feb 2018 15:54
Please see now.
That is not what I asked for.

Re: how to read file name with spaces?

Posted: 09 Feb 2018 16:22
by Squashman
Two options for you.

Code: Select all

for /f "delims=" %%v in ('dir /b %allPdfFiles%\*.pdf') do (
  "%pdfToText%" "%allPdfFiles%\%%v" "%allTxtFiles%\%%~nv.txt" >NUL 2>&1 || echo Error converting %%v
)

Code: Select all

for %%v in ("%allPdfFiles%\*.pdf") do (
  "%pdfToText%" "%%~v" "%allTxtFiles%\%%~nv.txt" >NUL 2>&1 || echo Error converting %%v
)

Re: how to read file name with spaces?

Posted: 10 Feb 2018 16:29
by lalat06bag
Thank you. This is perfect.