Search code examples
batch-filedirectoryrenamebatch-rename

Batch Renaming Folders


I have about 3000 seperate folders all named like this

0001 Game 1

0002 Game 2

0003 Game 3

is there any way i can rename them in a batch so they end up like This

Game 1

Game 2

Game 3


Solution

  • Here is how you can loop over only the files that begin with 4 digits followed by a space.

    First you run this batch file and look at the output to make sure that everything is going to be renamed correctly:

    @echo off
    for /f "usebackq tokens=1,*" %%a in (`dir /ad /b "." ^| findstr /r "^[0-9][0-9][0-9][0-9] "`) do (
        echo Renaming [%%~a %%~b] TO [%%~b]
    )
    

    Then you run this one (which is the same script, except it replaced the echo statement with a real rename command) to do the renaming:

    @echo off
    for /f "usebackq tokens=1,*" %%a in (`dir /ad /b "." ^| findstr /r "^[0-9][0-9][0-9][0-9] "`) do (
        ren "%%~a %%~b" "%%~b"
    )