windows - Batch file for file merge -
i have 1 folder inside there 15 sub folder folder1, folder2, folder3, etc... each subfolder (folder1, folder2) has 2 or 3 level subfolders. each folder has .txt files. create batch file can 15 create merge files each folder.
i can cmd commands for %f in (*.txt) type "%f" >> output.txt
.
in above command, need open 15 different command prompt windows , run above command.
is there way can achieve programmatically in batch file?
the following batch create in direct subfolders of mainfolder
file merge.txt containing text files of subfolder , below. inserts header full path each text file , appends empty line avoid joining lines if last line of file doesn't end cr/lf.
@echo off set "mainfolder=c:\pathto\wherever" /d %%a in ("%mainfolder%\*") ( /f "delims=" %%b in ('dir /b/s "%%a\*.txt" 2^>nul^|find /v "merge.txt"') ( echo ==== %%~fb ==== type "%%~fb" echo: ) " ) > "%%~fa\merge.txt
Comments
Post a Comment