批处理根据文件修改时间删除文件名最后几个字符不同的文件

2024-12-02 05:39:26
推荐回答(2个)
回答1:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir/b/o-d *.txt') do (
set s=%%i
set s=!s:~,8!
if defined #!s! (del %%i) else set #!s!=1
)

回答2:

if not exist OLD md OLD
for /f "delims=" %%f in ('dir /b *.txt') do (set a=%%f
set #%a:~0,8%=%a:~0,8%)
for /f "tokens=2 delims=^=" %%f in ('set #') do (
for /f "skip=1 delims=" %%x in ('dir /b /o-d %%f*.txt') do move %%x OLD\)