Rename Multiple files with in Dos batch file

后端 未结 3 834
时光取名叫无心
时光取名叫无心 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:07

    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?

    ::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 contained cat.txt, dog.txt, bird.txt, ninjaturtle.txt, it will output 1.txt, 2.txt, 3.txt, 4.txt.

提交回复
热议问题