。bat使用现有字符重命名文件夹中的所有文件,但反转

问题描述 投票:0回答:0

AccountStatement_10062023.pdf AccountStatement_10072023.pdf AccountStatement_10082023.pdf AccountStatement_10092023.pdf AccountStatement_10102023.pdf

我想通过运行一个简单的蝙蝠文件将其重命名为:

AccountStatement_20230610.pdf
AccountStatement_20230710.pdf
AccountStatement_20230810.pdf
AccountStatement_20230910.pdf
AccountStatement_20231010.pdf

我有一个蝙蝠文件,该文件使用系统日期邮票重命名文件,如下所示:

forfiles /M * /C "cmd /c echo @fdate @ftime @file"
for /f "tokens=1-3" %%a IN ('forfiles /M NORM*.MP4 /C "cmd /C echo @fdate @ftime @file"') do (
 set line1=%%a
 set line2=%%b
 set line1r=!line1:/=-!
 set line2r=!line2::=-!
:echo print %%a %%b %%c
FOR /f "tokens=1-7 delims=/.:- " %%M in ("%%a %%b") DO (
SET Day=%%M
SET Month=%%N
SET Year=%%P
SET Hours=%%Q
SET Minutes=%%R
SET Seconds=%%S
set line3=%%O%%N%%M
set line4=%%P-%%Q
set line3r=!line3!
set line4r=!line4!
)
 rename %%c "CTNORM !line3r! !line4r!.*"
)

但这略有不同,因为我需要使用现有的文件名,而日期格式更改为yyyymmdd,其当前名称为ddmmyyyyyy。

任何帮助的人都非常感谢。 dave
	

如果您不需要在文件名的日期部分执行验证,那么以下内容可能是您需要的,

(存储在源目录中并双击)。

@Echo Off SetLocal EnableExtensions DisableDelayedExpansion For /F "Delims=" %%G In ('Set "PATHEXT=" ^& %SystemRoot%\System32\where.exe .:"AccountStatement_????????.pdf" 2^>NUL') Do (Set "_=%%~nG" SetLocal EnableDelayedExpansion For /F "Delims=" %%H In ("!_:~,-8!!_:~-4!!_:~-6,2!!_:~-8,2!" ) Do EndLocal & Ren "%%G" "%%H%%~xG")

file batch-file rename
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.