把以下代码放入txt文本文件中,并修改后缀txt为bat。双击运行
[PowerShell] 纯文本查看 复制代码@echo off
setlocal enabledelayedexpansion
REM 配置参数 --------------------------
set START_YEAR=1985
set END_YEAR=2025
REM -----------------------------------
for /l %%Y in (%START_YEAR%,1,%END_YEAR%) do (
if exist "%%Y" (
echo 正在处理 %%Y 年度文件...
pushd "%%Y"
for /l %%m in (1,1,12) do (
set "month=0%%m"
md "!month:~-2!" >nul 2>&1
move "%%Y!month:~-2!??" "!month:~-2!\" >nul 2>&1
)
新建文本,保存以下代码为bat后缀,放主文件夹执行批处理就可以了
[Bash shell] 纯文本查看 复制代码@echo off
setlocal enabledelayedexpansion
for /d %%y in (*) do (
if "%%y" geq "1900" if "%%y" leq "2100" (
cd "%%y"
echo 正在处理年份目录:%%y
for /l %%m in (1,1,12) do (
set month=0%%m
set month=!month:~-2!
mkdir !month! >nul 2>&1
)
for /f "tokens=*" %%f in ('dir /b') do (
if /i not "%%~xf" == ".bat" (
set fname=%%~nf
if not "!fname:~2!" == "" (
set mmonth=!fname:~4,2!
if exist "!mmonth!\" (
move "%%f" "!mmonth!\" >nul
)
)
)
)
cd..
)
)
echo 文件整理完成!
@ping 127.0.0.1 -n 3 >nul
以下是成品链接,已测试兼容文件及文件夹
https://www.123684.com/s/r8wZVv-wUjgh?提取码:vJqs