Windows batch - concatenate multiple text files into one

前端 未结 9 578
醉梦人生
醉梦人生 2021-01-31 13:53

I need to create a script, which concatenates multiple text files into one. I know it\'s simple to use

type *.txt > merged.txt

But the require

9条回答
  •  醉梦人生
    2021-01-31 14:53

    Try this:

    @echo off
    set yyyy=%date:~6,4%
    set mm=%date:~3,2%
    set dd=%date:~0,2%
    
    set /p temp= "Enter the name of text file: "
    FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%temp%.txt
    

    This code ask you to set the name of the file after "day_" where you can input the date. If you want to name your file like the actual date you can do this:

    FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%yyyy%-%mm%-%dd%.txt
    

提交回复
热议问题