how to read file name with spaces?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

how to read file name with spaces?

#1 Post by lalat06bag » 09 Feb 2018 14:42

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?
Last edited by Squashman on 09 Feb 2018 15:31, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: how to read file name with spaces?

#2 Post by Squashman » 09 Feb 2018 15:32

Turn ECHO ON at the top of your script and show us all the console output processing that one specific file.

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: how to read file name with spaces?

#3 Post by lalat06bag » 09 Feb 2018 15:54

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: how to read file name with spaces?

#4 Post by Squashman » 09 Feb 2018 16:18

lalat06bag wrote:
09 Feb 2018 15:54
Please see now.
That is not what I asked for.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: how to read file name with spaces?

#5 Post by Squashman » 09 Feb 2018 16:22

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
)

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: how to read file name with spaces?

#6 Post by lalat06bag » 10 Feb 2018 16:29

Thank you. This is perfect.

Post Reply