Rename multiple files in a Dos batch file

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

How can i do this?

+6
source share
3 answers

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

Change Change the mathematical operation to a cleaner solution proposed by Andrey.

 @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 
+11
source

First create a list of directories:

 dir /b *.txt > myfile.cmd 

Then run UltraEdit ( http://www.ultraedit.com/ ) and open the file.

Then go into column mode, select all rows and:

  • insert "RENAME" at the beginning of each line
  • insert ".TXT" at the end of each line (remember to make it far enough if you have very long lines)
  • insert the number (see "Column / Insert number in the menu") before .TXT
+1
source

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

How can i do this?

 ::Setup the stage... SETLOCAL ENABLEDELAYEDEXPANSION SET folder=C:\This\Is\The\Folder SET count=1 ::Action CD "%folder%" FOR %%F IN ("*.txt") DO ( MOVE "%%F" "!count!.txt" SET /a count=!count!+1 ) ENDLOCAL 

Shorthand

 SETLOCAL ENABLEDELAYEDEXPANSION SET count=1 FOR %%F IN (C:\Path\To\File\*.txt) DO MOVE "%%~fF" "%%~dpF!count!.txt" & SET /a count=!count!+1 ENDLOCAL 

So, if your folder contains cat.txt, dog.txt, bird.txt, ninjaturtle.txt, it will output 1.txt, 2.txt, 3.txt, 4.txt.

+1
source

Source: https://habr.com/ru/post/890609/


All Articles