Search code examples
dosrename

Change several windows folder names at once


I have to rename several folders. The old folders were randomly named, and the new names allow for a consistent naming protocol. i have reconciled the existing folders with the list of new names, but there are hundreds of folders to rename and to do it manually will take forever.

the old name and new name are generally very different. for example:

old: john l,smth new: smith_john_04082013

so what i would like to do is place a list of the old names in one part of a program and the list of new names in another part, and then loop down the list of folders renaming them until the last one is done.

for example

john l,smth (to) smith_john_04082013
mary-jones 42nd street (to) jones_mary_03122013
wil-h-davis (to) davis_william_02122012

etc

i know how to use the rename command in dos, but all that 'seems' to do is just change the name of of one directory, ie rename "john l,smth" "smith_john_04082013"

i tried doing something like:

rename "john l,smth" "smith_john_04082013"; "mary-jones 42nd street" "jones_mary_03122013"; "wil-h-davis" "davis_william_02122012"

the concept being maybe using a separator was the trick to a multiple rename, but that didn't work either.

if anyone knows how to do this that would be very helpful.

TIA


Solution

  • Just create a batch file (plain text file with a .bat extension, like rename_folders.bat), and list each operation as a single line:

    ren "john l,smth" "smith_john_04082013"
    ren "mary-jones 42nd street" "jones_mary_03122013"
    ren "wil-h-davis" "davis_william_02122012"
    

    (ren is the short name for rename, which saves a little typing.)

    Once you have all the lines in the file, save it in the folder where you want it to run, open a command prompt in that folder, and just run the batch file (the .bat extension is optional when you run it, as it's one of the known executable file extensions):

    C:\YourBaseFolder>rename_folders
    

    or

    C:\YourBaseFolder>rename_folders.bat