批处理文件将特定文件合并为一个?



我是Windows批处理命令的新手,所以请饶恕我任何不相关的帮助。 基本上我想使用 windows 的类型命令合并某些文件,但由于这些文件来自各种来源,我需要在文件名中搜索源过滤器并仅合并这些文件。我尝试编写下面的代码,但它不适合我。

@echo off
set filter=%1
set final_file=%2
echo %filter%
echo %final_file%
for %f in (*.dlt) do(
echo %f
if find %filter "%f ( 
do type "%f" >> %final_file
)
)

这是我将所有*.bat文件合并到一个文件中的示例; 因此您可以根据需要轻松修改它: 只需要修改变量Set "Filter_Ext=dlt"Set "MasterFolder=%userprofile%desktop"即可

@echo off
Mode 75,3 & Color 9E
Title Merge all *.bat in one file
Set "MasterFolder=%userprofile%desktop"
Set "OutPut=Output_Merged_Files.txt"
Set "Filter_Ext=bat"
If exist "%OutPut%" Del "%OutPut%"
echo(
echo           Please Wait a while we generate the output file ...
@For /f "delims=" %%a in ('Dir /s /b /A-D "%MasterFolder%*.%Filter_Ext%"') Do (
cls
echo(
echo          Please Wait a While ...   Merging "%%~nxa" ...
(
echo ====================================================
echo  Contents of "%%a"
echo ====================================================
Type "%%a"
echo(
)>> "%OutPut%"
)
Start "" "%OutPut%"

编辑 将所有 .dlt 合并到一个文件中

@echo off
Mode 75,3 & Color 9E
Title Merge all *.dlt in one file
Set "MasterFolder=%~1"
Set "OutPut=Output_Merged_Files.txt"
Set "Filter_Ext=dlt"
Set "KeyWord=Engine"
If exist "%OutPut%" Del "%OutPut%"
echo(
echo           Please Wait a while we generate the output file ...
@For /f "delims=" %%a in ('Dir /s /b /A-D "%MasterFolder%*.%Filter_Ext%" ^|find /I "%KeyWord%"') Do (
cls
echo(
echo          Please Wait a While ...   Merging "%%~nxa" ...
(
echo ====================================================
echo  Contents of "%%a"
echo ====================================================
Type "%%a"
echo(
)>> "%OutPut%"
)
Start "" "%OutPut%"

相关内容

最新更新