1

Is there a way to change the file extensions of existing files (inside a folder) simultaneously?

I have a folder and within are different subfolders (nested). All the files are .txt, and I want to change them all to .md.

Is there a way to change those simultaneously, or do I really need to modify them one by one? :-(

Thanks, Faye

Additional questions:

@user1016274 : Thanks. By the way, will it also work with files with no extensions? I haven't tried it yet, but I discovered just now that some folders have files with no extension. Pls see the image I added (above), pls see it. Thanks.

enter image description here

3
  • Run cmd, go to the directory where the files reside, and type ren *.txt *.md.
    – AFH
    Dec 1 '17 at 11:46
  • @AFH : Thanks for the reply, but that solution won't be good in my case, because I have multiple deeply nested folder structure. Doing that would mean I have to do it in every single folder, every single subfolder, every folder inside all subfolders, etc. Is there any other solution? Thanks, Faye..
    – Faye
    Dec 1 '17 at 11:50
  • If I'd been at my computer when you responded, I'd have given you user1016274's answer. Note that ren and rename are synonyms.
    – AFH
    Dec 1 '17 at 14:01
2

The rename command allows for a wildcard:
rename *.txt *.md would rename all files in one call, in the current directory.

Now you just need to traverse all directories down from the root dir. For this, there is a for command:
cd /d <rootdir> & for /R %d in (.) do @echo %d

Putting it all together:

cd /d <rootdir>
for /R %d in (.) do @rename "%d\*.txt" *.md
6
  • Can you pls make it a bit clearer to me. Do I need to type that 'as is', and I just need to change the <rootdir> and put my directory name, ie ie: <E:\Documents\Freelance\Project22\> ? Thanks, Faye
    – Faye
    Dec 1 '17 at 11:55
  • Yes, exactly. To be safe, you could make a test run with do @dir /b %d\*.txt. You will see an error message for each directory which does not contain any '.txt' file. Dec 1 '17 at 12:00
  • Thanks, I will experiment with that later at home, and will mark this as correct answer if I got it right. Thanks.
    – Faye
    Dec 1 '17 at 12:07
  • Please note: I added quotation marks to take care of directories containing spaces in their names. And secondly, the syntax is correct for running the command from a command line, not within a batch file. Within a batch file, you need to double each '%' character. Dec 1 '17 at 12:10
  • Thanks. By the way, will it also work with files with no extensions? I haven't tried it yet, but I discovered just now that some folders have files with no extension. Pls see the image I added (above), pls see it. Thanks. Those are also text files (book stories), I can view them and edit them in VS-Code, but they have no extensions.
    – Faye
    Dec 1 '17 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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