Renaming file based on its content using Batch file

前端 未结 1 1710
难免孤独
难免孤独 2020-12-12 07:54

I need a batch file that reads the description name present in the nest.txt file and rename that file name based on description name.

For example i have a file name

相关标签:
1条回答
  • 2020-12-12 08:44

    The following batch file takes one command line parameter and must be run from the folder where the files to be renamed exist. You could easily add more code to the batch file to make it more intelligent (e.g., change to the folder, hard code *.txt in place of %1, etc.).

    So, if the batch file is called fixfilenames.bat and is in the same folder with the TXT files, from a command prompt, type fixfilenames *.txt and it will rename the files first to have the extension temp_txt so that the for loop won't pick up the files again after they are renamed. Then when it is done, it renames all temp_txt files to txt files.

    @echo off
    
    for %%i in (%1) do (
      for /f "tokens=2 delims==" %%j in ('findstr /B /I "Description=" "%%i"') do (
        ren "%%i" "%%j.temp_txt"
      )
    )
    
    ren *.temp_txt *.txt
    
    0 讨论(0)
提交回复
热议问题