- @echo off & setlocal enabledelayedexpansion
-
- :: 要合并的文件位置
- set sourcePath=%~dp0DATAS
- :: 目的文件夹
- set target=%~dp0DATAS\合并后
-
- :: 确认目的文件夹存在
- mkdir DATAS\Target >nul
- for /f "tokens=1-3* delims=-" %%a in ('dir /b /a-d "%sourcePath%"^|sort') do (
- set file=%%a-%%b-%%c-%%d
- if not defined %%a-%%b-%%c (
- echo;--------------------------------------------------
- echo;合并!file!...
- set %%a-%%b-%%c=1&set n=0
- for /f "delims=" %%i in (%sourcePath%\!file!) do (
- set /a n+=1
- if !n! leq 3 echo;%%i>>"%target%\%%a-%%b-%%c.%%~xd"
- )
- ) else (
- echo;合并!file!
- more +3 "%sourcePath%\!file!">>"%target%\%%a-%%b-%%c.%%~xd"
- )
- )
-
- pause & exit /b
复制代码
|