Batch file for file merge

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
HS1234
Posts: 2
Joined: 25 Jul 2017 16:17

Batch file for file merge

#1 Post by HS1234 » 25 Jul 2017 16:22

I have one folder inside that there 15 sub folder Folder1, Folder2, Folder3, etc... Each subfolder (Folder1, Folder2) has 2 or 3 level sub folders. Each folder has some .txt files. I would like to create a batch file that can 15 create merge files for each folder.

I can do it with cmd commands like

Code: Select all

for %f in (*.txt) do type "%f" >> output.txt.


In the above command, I need to open 15 different command prompt windows and run the above command.

Is there any way that I can achieve this programmatically like in a batch file?

I have tried a lot of available solution over the net but it did not work for me. I will try more solution.

I am very much new in DOS commands so any kind guidance is appreciated.

Thanks for your help.

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Batch file for file merge

#2 Post by Hackoo » 26 Jul 2017 05:40

Hi :)
You can do something like this batch script :

Code: Select all

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

You should just change the variable MasterFolder to yours ;)

Post Reply