Rename Multiple files with in Dos batch file

后端 未结 3 826
时光取名叫无心
时光取名叫无心 2020-12-18 06:04

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?

3条回答
  •  失恋的感觉
    2020-12-18 06:27

    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
    

提交回复
热议问题