汇总 | @echo off | | cd /d "%~dp0" | | set "dstdir=汇总" | | if not exist ".\%dstdir%" md ".\%dstdir%" | | for /f "delims=" %%A in ('dir /ad /b') do ( | | if /i not "%%A"=="%dstdir%" ( | | for %%B in ("a.txt" "c.txt") do ( | | if exist ".\%%A\%%~B" ( | | copy /y ".\%%A\%%~B" ".\%dstdir%\%%A%%~B" | | ) | | ) | | ) | | ) | | pause | | exit /bCOPY |
复原 | @echo off | | setlocal EnableDelayedExpansion | | cd /d "%~dp0" | | set "srcdir=汇总" | | if not exist ".\%srcdir%" md ".\%srcdir%" | | for /f "delims=" %%A in ('dir /a-d /b ".\%srcdir%\*a.txt" ".\%srcdir%\*c.txt"') do ( | | set "fname=%%A" | | set "dstdir=!fname:~,-5!" | | set "fname=!fname:~-5!" | | if not exist ".\!dstdir!" md ".\!dstdir!" | | copy /y ".\%srcdir%\%%A" ".\!dstdir!\!fname!" | | ) | | endlocal | | pause | | exit /bCOPY |
|