1

There is a file named doctitle.txt which contains the title. I want to use this title to rename another file, currently name file.pdf, so I did:

for /f "delims=" %%x in (doctitle.txt) do set "DOCTITLE=%%x"
move file.pdf %DOCTITLE%.pdf

This works fine, if there no space in the title string, i.e "DocumentTitle". But fails if there is a space in the title, i.e "Document Title".

What could be done to overcome this issue?

oqrxke
  • 331
  • 1
  • 3
  • 12

1 Answers1

1

Try:

for /f "tokens=*" %%x in (doctitle.txt) do set DOCTITLE=%%~x
move file.pdf "%DOCTITLE%.pdf"

That way, the variable DOCTITLE will not be surrounded with quotes as %%~ removes any quotes.

Quoting for /?:

%~I         - expands %I removing any surrounding quotes (")
Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • Let's say title is "açaí", then I want to use "acai" instead (replacing the accents). Would it be possible? – oqrxke Jul 01 '15 at 23:49
  • @oqrxke I'm not completely sure, but ask it as a different question so others can help – Monacraft Jul 02 '15 at 01:21
  • Thanks! I've posted a new question here http://stackoverflow.com/questions/31195236/batch-scritp-to-replace-accents-in-words. – oqrxke Jul 02 '15 at 21:51