Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename Multiple files with in Dos batch file

I wish to rename all files inside the folder *.txt, so the result will be "1.txt", "2.txt" and "3.txt", ....

How can I do so?

like image 810
JustMe Avatar asked Jun 15 '11 14:06

JustMe


People also ask

How do I rename multiple files in DOS?

Select the files you want to rename. Press F2 key. Type a new name for your files and then press Enter.

How do I batch rename multiple files at once?

You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.


1 Answers

The following may accomplish what you are looking for. It uses a for loop to iterate through the text files and makes a "call" to another bit of the batch file to do the rename and increment of a variable.

Edit Change math operation to cleaner solution suggested by Andriy.

@echo off
set i=1
for %%f in (*.txt) do call :renameit "%%f"
goto done

:renameit
ren %1 %i%.txt
set /A i+=1

:done
like image 70
Mark Wilkins Avatar answered Oct 02 '22 04:10

Mark Wilkins