How to Mass Rename Files Using CMD in Windows [Beginner Friendly]

Words
377
Reading
2 min
Listen
Play
9y

Heyy I'm back with another quick and easy to follow tutorial for you guys! In this guide, you will learn how to mass rename files using CMD in Windows. This always comes handy. And I'll show you how to do it in two ways; easier and a harder one (but more flexible).

EASY METHOD


The easy method is really easy to remember and you should use this method if you simply want to mass rename file extensions. Let's get started:

First, locate the files you want to rename.

To avoid the hustle of using cd in cmd, do this: while holding SHIFT, right click anywhere in your folder and click on "Open command window here" to open a cmd window in the folder.

Then after the CMD window opens, you can use the rename function. (Basically '*' means any files and because we put the extension after that it literally means every file ending on that extension)


rename *.avi *.newextension

Where you can change newextension to the extension you want.

After executing the command, the files now have the desired extension!

HARD METHOD


You should use the hard method if you want to change the names of the file too, not just the extensions.

First, start by opening a new notepad file and adding the code:

@echo off
set /p FileExtension= "What is the file extension of the files you wish to rename?"
set /p FileExtension2= "What is the new file extension that your files should have?"
set /p FileName= "What file name should the files have?"

setlocal EnableDelayedExpansion
set i=0
for %%a in (*.%FileExtension%) do (
    set /a i+=1
    ren "%%a" "%FileName%_!i!.newfile"
)
ren *.newfile *.%FileExtension2%

echo Action done.
cmd /k

DETAILED CODE EXPLANATION: (You can jump this if you are not interested in the coding process)

  1. Make three variables: FIleExtension, FileExtension2, FileName and get input to them.
  2. The setlocal EnableDelayedExpansion will cause variables within a batch file to be expanded at execution time rather than at parse time.
  3. Makes another variable 'i' for iteration purposes.
  4. Uses the FOR loop to iterate through the files and for each file found it adds 1 to i then renames the found file with the temporary extension .newfile (to avoid problems)
  5. After exiting the loop it renames the .newfile to the extension we provided.
  6. At the end it just prints 'Action done'
  7. The cmd /k just keeps the cmd from auto-exiting.

Then save the file with .bat extension:


Then all you need to do is start the saved file and enter what you're asked:

Hope you liked this guide and as always, if you have any question/problems just drop them down in the comment section!