for /r %%i in (*.txt) do ( / / 把目录下所有的TXT文件名存入变量I中
for /f "delims=" %%a in (%%i) do ( // 打开变量I代表的TXT文件,以行的方式读取TXT的内容,并把内容存入变量A中
if not "%%a"=="" move "%%i" "%%a.txt" &&goto :eof //如果变量A代表的内容不为空的话,就把变量I代表的文件名改为变量A代表的内容,并且退出循环
)
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.txt') do (
set n=
for /f %%j in (%%i) do (
if "!n!"=="" ren "%%i" "%%j.txt"
set n=found
)
)
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.txt') do (
set n=
for /f "delims=" %%j in (%%i) do (
if "!n!"=="" ren "%%i" "%%j.txt"
set n=found
)
)