-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.

  • This is really lame. The answer is that text file no longer support page breaks because printers no longer support `/b` escape codes. If you want to have real working page breaks then you'll need to convert this to something else. I would suggest html if you want to print this. If you want page breaks for formatting alone then it cannot be done because almost no text editors support that escape code anymore (which once again is because it is useless when printing anyway). – krowe Mar 07 '15 at 15:19
  • You could count lines but that'll only work for a specific font and font size. You haven't given us that and even if you did it would be a pain to figure out for you. If you wanted to do this then just go here: http://stackoverflow.com/questions/5664761/how-to-count-no-of-lines-in-text-file-and-store-the-value-into-a-variable-using – krowe Mar 07 '15 at 15:21
  • @manutd Please don't keep changing your question to add new requirements after you have already have an answer. If you have another question, please ask it by clicking the [Ask Question](http://$SITEURL$/questions/ask) button. – DavidPostill Mar 15 '15 at 14:16

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,493
  • 1
  • 24
  • 31
  • @manutd See my update. – krowe Mar 07 '15 at 15:26
  • @manutd FYI, it is customary for the OP to not only accept an answer but to also upvote all answers which make a good attempt. Also, it did work. Just go to look at it in the print preview dialog. It'll print just as you asked. – krowe Mar 07 '15 at 15:39
  • @manutd See my update. Then upvote me. – krowe Mar 07 '15 at 16:11
  • No. Just echo the text that you want (do that before the TYPE line). Use something like this: `echo See, this is easy!` – krowe Mar 07 '15 at 16:34
  • @manutd Try something like this answer suggests: http://stackoverflow.com/a/10945887/932549 for the final little bit of this. Also don't forget to up vote all questions which helped you. – krowe Mar 16 '15 at 02:59