用于增量重命名 files/folders 日期的批处理文件
Batch file for incremental renaming of files/folders with date
我有一个名为 Output
的文件夹。我想使用批处理文件将其重命名为 Output_old05Aug15
,其中 05Aug15
是今天的日期。但是,如果 Output_old05Aug15
已经存在,则 Output
将重命名为 Output_old05Aug15_2nd
,依此类推。我只需要一个相应地重命名文件夹的批处理文件。
编辑:
必须逐步重命名已经存在的文件夹。这是我所做的:
@ECHO OFF
SETLOCAL
for /D %%f in (.\Output) do (
IF EXIST "Output_old*" (
SET reqren=Y
FOR /l %%x IN (2,1,999) DO IF DEFINED reqren IF NOT EXIST "Output_old_%%x" (rename "%%f" "Output_old_%%x"&SET "reqren=")
) ELSE (rename "%%f" "Output_old")
)
GOTO :EOF
我提到了这个postBATCH File - Rename and Incremental folder number?
@echo off
setlocal EnableDelayedExpansion
rem US locale, ie: 'Thu 08/06/2015'
for /F "tokens=2 delims=/ " %%m in ("%date%") do set /A "n=(3*((1%%m)%%100-1))"
set month=JanFebMarAprMayJunJulAugSepOctNovDec
set monthName=!month:~%n%,3!
set dt=%date:~7,2%%monthName%%date:~-2%
if exist Output (
for /l %%x in (1,1,999) do (
if %%x EQU 1 set new=Output_old%dt%
if %%x GEQ 2 set new=Output_old%dt%v%%x
if not exist !new! (
echo !new!
rename output !new!
goto fin
)
)
)
:fin
我会把适当的序号指标留给你。请注意,%date% 格式取决于语言环境,因此在美国的情况下,您将首先使用 tokens=1 delims=/
for
我有一个名为 Output
的文件夹。我想使用批处理文件将其重命名为 Output_old05Aug15
,其中 05Aug15
是今天的日期。但是,如果 Output_old05Aug15
已经存在,则 Output
将重命名为 Output_old05Aug15_2nd
,依此类推。我只需要一个相应地重命名文件夹的批处理文件。
编辑: 必须逐步重命名已经存在的文件夹。这是我所做的:
@ECHO OFF
SETLOCAL
for /D %%f in (.\Output) do (
IF EXIST "Output_old*" (
SET reqren=Y
FOR /l %%x IN (2,1,999) DO IF DEFINED reqren IF NOT EXIST "Output_old_%%x" (rename "%%f" "Output_old_%%x"&SET "reqren=")
) ELSE (rename "%%f" "Output_old")
)
GOTO :EOF
我提到了这个postBATCH File - Rename and Incremental folder number?
@echo off
setlocal EnableDelayedExpansion
rem US locale, ie: 'Thu 08/06/2015'
for /F "tokens=2 delims=/ " %%m in ("%date%") do set /A "n=(3*((1%%m)%%100-1))"
set month=JanFebMarAprMayJunJulAugSepOctNovDec
set monthName=!month:~%n%,3!
set dt=%date:~7,2%%monthName%%date:~-2%
if exist Output (
for /l %%x in (1,1,999) do (
if %%x EQU 1 set new=Output_old%dt%
if %%x GEQ 2 set new=Output_old%dt%v%%x
if not exist !new! (
echo !new!
rename output !new!
goto fin
)
)
)
:fin
我会把适当的序号指标留给你。请注意,%date% 格式取决于语言环境,因此在美国的情况下,您将首先使用 tokens=1 delims=/
for