Rename file based on file Content batch file

前端 未结 3 1106
眼角桃花
眼角桃花 2020-12-19 23:44

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

For example i have a file name c

相关标签:
3条回答
  • 2020-12-20 00:09

    This will get you started.

    for /f "tokens=1,* delims==" %%A in ('find /i "Description" "nest.txt"') do echo %%B
    
    0 讨论(0)
  • 2020-12-20 00:11

    try this:

    for /f "skip=1 tokens=1* delims==" %%i in (nest.txt) do ren XYZ.txt "%%~j.txt"
    
    0 讨论(0)
  • 2020-12-20 00:12

    I assume, you have 1000 files with 1000 different names.

    @echo off
    for /f %%i in ('dir /b *.txt') do (
      for /f "skip=1 tokens=1* delims==" %%j in ( %%i ) do ( 
        if "%%j"=="Description" echo ren "%%i" "%%k.txt" 
      )
    )
    

    This will not work on files which have spaces in their (original) filename, but I don't understand, why. (%%i contains only the part before the first space). Maybe someone other can help with this (I'm sure, it's only a minor change, but I can't find it)

    Remove the "echo", if the output fits your needs.

    (are you sure that all 1000 files have 1000 different Descriptions?)

    0 讨论(0)
提交回复
热议问题