I am trying to make a program to make a file that echoes the contents of a file into a new one. For example:
If I had a file named foo.txt with the contents of:
@echo off
echo Hello World
pause
exit
The file would create a separate one that has the contents of:
@echo off
color a> foo2.txt
echo @echo off>> foo2.txt
echo echo Hello World>> foo2.txt
echo pause>> foo2.txt
echo exit>> foo2.txt
However, I have come across a problem. If I add an exclamation mark to the file:
@echo off
echo Hello World!
pause
exit
It would not include the exclamation mark in the file.
How would I go about fixing this?
My Code:
@echo off
setlocal enabledelayedexpansion
:input
set /p "input=Input Filename: "
if not exist "%input%" goto input
cls
set /p "output=Output Filename: "
cls
echo @echo off> "%input%-Echo.bat"
echo color a^> "%output%">> "%input%-Echo.bat"
for /f "usebackq delims=" %%A in ("%input%") do (
set "line=%%A"
set "line=!line:^=^^!"
set "line=!line:<=^<!"
set "line=!line:>=^>!"
set "line=!line:&=^&!"
set "line=!line:|=^|!"
set "line=!line:(=^(!"
set "line=!line:)=^)!"
set "line=!line:%%=%%%%!"
echo(echo !line! ^>^> "%output%" >> "%input%-Echo.bat"
)
echo The process has been completed. The file is called "%input%-Echo.bat"
echo.
<nul set /p=Press any key to exit . . .
pause>nul
exit