I have this script in a .bat file which unifies all the lines of a .txt into one, deleting the newlines (/n):
@echo off
setlocal EnableDelayedExpansion
set row=
for /f %%x in (file.txt) do set "row=!row!%%x"
>newfile.txt echo %row%
And it works perfectly, but now I want it to run only if "file.txt" exists. Otherwise, it's always going to create an empty "newfile.txt" file. Then I tried with:
@echo off
if exist file.txt (
setlocal EnableDelayedExpansion
set row=
for /f %%x in (file.txt) do set "row=!row!%%x"
>newfile.txt echo %row%
)
But in "newfile.txt" the result is different: "ECHO is disabled".
I can do it with Powershell, but I want to do it with CMD and then unify it with other scripts in a single .bat file.
Thank you very much for your help.