本帖最后由 WHY 于 2020-10-15 09:20 编辑
- @echo off
- setlocal enabledelayedexpansion
- REM 查找png文件,其上上一级目录名为单个数字
- for /f "delims=" %%i in ('dir /b /a-d /s *.png ^| findstr "\\[0-9]\\[^\\]*\\[^\\]*$"') do (
- REM 当前png所在目录
- set "curPath=%%~dpi"
- if /i "!prePath!" NEQ "!curPath!" (
- REM png文件的上上一级目录名
- for %%j in ("%%i\..\..") do set /a n = "(%%~nj + 1) * 1000 + 100001"
- if defined prePath (
- for %%j in ("!prePath!.") do (
- md "!prePath!..\..\%%~nxj" 2>nul
- move "!prePath!*.png" "!prePath!..\..\%%~nxj\"
- )
- )
- ) else (
- set /a n+=1
- )
- REM 前一个png所在目录
- set "prePath=%%~dpi"
- ren "%%i" "!n:~1!%%~xi"
- )
- if defined prePath (
- for %%j in ("!prePath!.") do (
- md "!prePath!..\..\%%~nxj" 2>nul
- move "!prePath!*.png" "!prePath!..\..\%%~nxj\"
- )
- )
- REM 删除空目录
- for /f "delims=" %%i in ('dir /b /ad /s ^| sort /r') do rd "%%i" 2>nul
- pause
复制代码
|