-2

I have got plenty of *.cpp files in my directory. I have successfully merged file using the below command which i got from one of the sites online.

for %f in (*.cpp) do type "%f" >> Merged.doc 

Now i have a file (Merged.doc) with the contents of all my .cpp files. I want to add blank page at the end of each .cpp while merging or would like to have each .cpp files in different pages in the Merged file .

As the below command (from another question). Is there any command similar to :

type *.cpp > merged.doc

Here each file starts after a newline, like this it should start in a new page.

EDIT

What if i need to add a four lines of text before each program.

Suppose if i want to add the Date associated with each file in the line Date : DD-MM-YYYY and the file name with File Name : abcd.cpp(I don't want his .cpp).

What i did :

 @echo off
 cd C:\programs
 echo ^<html^>^<head^>^<style^> pre {page-break-after: always;} ^</style^>^</head^>^<body^>      >merged.html
 for /r %%f in (*.cpp) do (
 echo ^<pre^>
 echo File Name        :(Here i want the date associated with each file without the extension .cpp) 
 echo File Description :
 echo Author           :Name
 echo Date             :(Here the date associated with each program)
 echo.
 type "%%f"
 echo ^</pre^>
 ) >>merged.html
 echo ^</body^>^</html^> >> merged.html

ERROR in the resultant file

After #include there is no <isotream.h> or <conio.h> or <string.h> or <proccess.h>.But with my original program file it is all available. It does not have the whole program only the half part of each program is on the resultant file. I'm new to batch scripting. What is wrong with my batch file.

1 Answers1

0

This should do the trick:

@echo off
break>merged.cpp
for /r %%f in (*.cpp) do (
    type "%%f"
    for /l %%x in (1, 1, 100) do echo.
) >> merged.cpp

This is written to be ran from a batch file. If you're typing his out each time then you're wasting your time. Change the 100 to any number of returns you'd like.

Update

If HTML is fine then use this:

@echo off
cd C:\test
echo ^<html^>^<head^>^<style^> pre {page-break-after: always;} ^</style^>^</head^>^<body^> >merged.html
for /r %%f in (*.txt) do (
    echo ^<pre^>
    echo See, this is easy!
    echo File Name: %%f
    echo Author: The Dude
    echo.
    type "%%f"
    echo ^</pre^>
) >> merged.html
echo ^</body^>^</html^> >> merged.html

Update 2

If you want to get this into Word correctly (without buying the pro version of Acrobat) then you just want to print the document to a pdf file. Then open that pdf file in Word (just like you would open a *.doc file). Word will covert it correctly only if done exactly like I've explained (you should see a message box asking you weather you want to continue with the conversion after you click open).

Oh and your question about adding 4 lines of text before each source file shows that you've learned nothing from what I've shown you. Look at the first part of my answer again and take a good guess as to how that would be done.

krowe
  • 5,629