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

时间:2017-07-28 08:11:04

标签: batch-file

我是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
    )
)

1 个答案:

答案 0 :(得分:1)

这是我在一个文件中合并所有*.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%"