6

I have folder (say c:\folder) in which many files reside. All of them are HTML documents. But some of them have not .html extension. I want to add them .html file extension using command prompt at once.

All the files which have not extension end with ^ character. All the file names have different lengths.

I have tried

ren *^ *^.html

but it did not rename all the files and prompted that

There is already an existing file with same name or file could not be found

3 Answers 3

2

^ is an escape character in cmd.exe. You have to escape it. Try ren *^^ *^^.html.

10

I try this and it works :

  C:\test>ren *. *.html

enter image description here


Update : with ^ in the name :

enter image description here

13
  • Thanks but not all the files to be changed. Just the files which have no extension Jun 19, 2014 at 20:58
  • @ÖzkanÖZLÜ Just the files that haven't extension will change.Others will remain unchanged. Jun 19, 2014 at 21:01
  • for example I tried with "a^" and "b.html" in "test" folder. And after, I have a^.html and b.html inside. Jun 19, 2014 at 21:04
  • @user3580433 you can't see the rename for b.html because it was earlier b.html itself :\ in other words, it is renamed but because prior to rename the filename & extension was same you think it's not changed
    – Sathyajith Bhat
    Jun 20, 2014 at 6:46
  • 1
    I have got 'The syntax of the command is incorrect' when I apply the following command: ren *. *.html Jun 22, 2014 at 12:30
2

The following works (you may wish first to add echo before the ren to make sure that the command is doing what you want):

for %f in (*.) do ren "%f" "%f.html"

You need the quotes in case the file name has embedded blanks.

2
  • this did not work. neither an error did not occur, nor a change Jun 22, 2014 at 11:58
  • It works perfectly for me. Make sure that you can see the files you want to rename when you type for %f in (*.) do echo %f. If not, post a dir listing and I'll recreate the same file names and see what happens.
    – AFH
    Jun 23, 2014 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.