Search code examples
batch-filecommand-linerenamefile-renamebatch-rename

How to rename files with list of names using command prompt?


I have a folder with multiple files. All files names looks like:

"1 зелен.doc"
"2 будда.doc"
"3 конфуций.doc"

All files are in order of first number that are in the beginning of the names. I have a list of filenames, that contains in text file. Each line in the text file is also in order. So, the first line is the name for the first file name, the second line is second file name and so on. How to rename files using command prompt?

Thank you very much!


Solution

  • @echo off
    setlocal EnableDelayedExpansion
    
    rem The list of filenames will be read from redirected Stdin
    < filenames.txt (
    
       rem Process the files via FOR command
       for %%a in (*.*) do (
    
          rem Read the next name from the list
          set /P name=
    
          rem Rename the file
          ren "%%a" "!name!"
    
       )
    )