Reputation: 564
I wrote a little batch script to parse my html file into a cpp-Header file so I can compile it to an ESP8266 (PROGMEM). The Script is really simple:
@echo off
set /P filename=Enter File name (w/o .html extension):
if exist "..\website\%filename%.html" (
echo|set /p dummyvar=%filename%>beforetemp.txt
type before.txt beforetemp.txt before2.txt "..\website\%filename%.html" after.txt > "..\server\%filename%html.h"
) else (
echo FILE at website\%filename%.html DOES NOT EXISTS!
pause
)
exit 0
Everything worked just fine before I added the part where I can input the name of the file I want to copy.
The all done file should look like this:
#include <arduino.h>
const char indexhtml[] PROGMEM = R"====(
<html>
...
</html>
)====";
But as I run the script it inserts a space character at the end of beforetemp.txt and therefore screws up the variable name in my indexhtml.h file. The stuff with before.txt beforetemp.txt before2.txt becomes
#include <arduino.h>
const char index html[] PROGMEM = R"====(
instead of
#include <arduino.h>
const char indexhtml[] PROGMEM = R"====(
The Question is: How can I print the content of %filename% between before.txt and before2.txt into my new file?
Here are the used files:
before.txt
#include <arduino.h>
const char
before2.txt
html[] PROGMEM = R"====(
after.txt
)====";
Upvotes: 0
Views: 522
Reputation: 564
As I stated the problem was in the line where I echoed %filename% into my temp-file. I changed the line
echo|set /p dummyvar=%filename%>beforetemp.txt
to
< nul set /P ="%filename%">beforetemp.txt
and everything works fine now.
The complete batch-file now looks like this:
@echo off
set /P filename=Enter File name (w/o .html extension):
if exist "..\website\%filename%.html" (
< nul set /P ="%filename%">beforetemp.txt
type before.txt beforetemp.txt before2.txt "..\website\%filename%.html" after.txt > "..\server\%filename%html.h"
) else (
echo FILE at website\%filename%.html DOES NOT EXISTS!
pause
)
exit 0
Upvotes: 0
Reputation: 38718
I would suggest with the following content:
before.txt
#include <arduino.h>
const char
before2.txt
html[] PROGMEM = R"====(
after.txt
)====";
that you use the following batch file, using Copy
instead of Type
:
@Echo Off
Set /P "filename=Enter HTML file name without extension: "
If Not Exist "..\website\%filename%.html" (
Echo website\%filename%.html does not exist.
%__AppDir__%\timeout.exe /T 5 /NoBreak > NUL
Exit /B 2
)
< NUL Set /P "=%filename%" > "beforetemp.txt"
Copy "before.txt" + "beforetemp.txt" + "before2.txt" + "..\website\%filename%.html" + "after.txt" "..\server\%filename%html.h" /B
Exit /B %ErrorLevel%
Please note that this does not currently delete your, probably now not required, beforetemp.txt
, so you may wish to incorporate a method of doing that before exiting.
Upvotes: 3