0

I am trying to change the file extension of all .rtf-files to .doc in a folder and all subfolders.

I found a great solution here: Rename files in sub directories

But my file fails when it encounters long file-names (The syntax of the command is incorrect.)

for /r %%X in (*.rtf) do (
ren %%X *.doc
)

I am up for totally different solutions as well. Working in a large file-environment that has been changed to Office 365 that does not support rtf - but does support them when renamed to doc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SoranDK
  • 3
  • 2
  • 1
    get used to enclose all file or path names in doublequotes: `ren "%%X" "*.doc"` – Stephan Feb 06 '17 at 15:46
  • Wow! How can that be it??? I have googled this for half an hour :-S Thanks! – SoranDK Feb 06 '17 at 15:49
  • 1
    It's worth mentioning that the source of the problem was not the length of the file name, but the fact that the file name contains spaces. – SomethingDark Feb 06 '17 at 15:55
  • Well it helps to debug your program. If you knew there was a problem with a specific file you should have seen a syntax error that had nothing to do with the file name being to long. – Squashman Feb 06 '17 at 16:39

1 Answers1

0

Enclose in quotes:

for /r %%X in (*.rtf) do (
ren "%%X" "*.doc"
)
Gordon Bell
  • 13,337
  • 3
  • 45
  • 64