0

我希望有人帮助我处理这段代码(如下所示)。我想要的只是新文件名需要是文件第一行的前 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
)

提前致谢...

4

1 回答 1

0

Try this:

@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"
)
于 2013-09-06T12:40:19.347 回答