How to merge text files with the same name from all subdirectories?

后端 未结 2 984
庸人自扰
庸人自扰 2021-01-29 02:23

I have several folders with files. Files can have the same names. I want to concatenate files into one of each name. Thanks in advance.

EDIT: I\'m sorry

2条回答
  •  我在风中等你
    2021-01-29 03:02

    merge.bat

    @echo off
    # for every text file in
    # the sub-dirs of current dir
    for /r "." %%a in (*.txt) do (
       # filename without path and extension
       echo %%~na
       # read file and append it to file with 
       # the same name prefix in current dir
       type %%a >> %%~na-merged.txt
    )
    

    merge_all_in_one.bat

    @echo off
    for /r "." %%a in (*) do (
        type %%a >> all_merged.txt
    )
    

提交回复
热议问题