我希望有人帮我这个代码(如下所示)。我想要的是新文件名需要是文件第一行的前32个字符吗?
cd c:\test2\test
for /f "delims=" %%i in ('dir /a-d /b *.txt') do (
set nname=
set fname=%%i
for /f "usebackq delims=" %%f in ("%%i") do if not defined nname set "nname=%%f"
setlocal enabledelayedexpansion
set "nname=!nname:~0,40!"
rename "!fname!" "!nname!"
endlocal
)
提前致谢...
答案 0 :(得分:0)
试试这个:
@echo off
setlocal enabledelayedexpansion
cd /d c:\test2\test
for /f "delims=" %%i in ('dir /a-d /b *.txt') do (
set nname=
for /f "usebackq delims=" %%f in ("%%i") do if not defined nname set "nname=%%f"
set "nname=!nname:~0,32!"
rename "%%i" "!nname!%%~xi"
)