user6498851 user6498851 - 7 months ago 16
HTML Question

adding html tags to multiple text files concatenated into one with a batch file

I have a couple of dozens of html files that I want to wrap with extra code

there is a header file: "header.txt" (div starts)

multiple text files: "Text1.txt", "Text2.txt" etc etc (text body)

and a footer file "footer.txt" (div ends)

so I've come up to this code after a bit of searching on stackoverflow:

type header.txt >> 1.txt & type Text*.txt >> 1.txt & type footer.txt >> 1.txt

EDIT: edited code to mirror text

The problem is I want the headers and footers before and after EACH text file, However what the code does is write the header then ALL of the text files and in the end the footer

I'm new to creating batch files so how can I separate the operations so that each Text file would have its own extra bits.

would I have to use for loops or is there a better way to do it?

Final EDIT (for future viewers): While the files are actually Text(.txt) Files (it comes from texteditor preference) the content is HTML code. It can be whatever you want....

Regarding the concatenation into one file.
After using ascii pfl code you can just append all of the files using copy command:

copy *New*.txt final.html


You could use a for loop to iterate through your (HMTL?) files Text*.txt and do the redirection (>) in its body, like this (see the explanatory remarks):

rem // `for` loop to walk through the files:
for %%F in ("Text*.txt") do (
    rem /* one redirection to output file, so output file is opened once;
    rem    the new files will have `_New` appended to their names: */
    > "%%~dpnF_New%%~xF" (
        type "header.txt" & rem // (write header to file)
        type "%%~fF"      & rem // (write original file content)
        type "footer.txt" & rem // (write footer to file)