Here is a picture:
.cmd file gives error was unexpected at this time.
Lukas Valancauskas
5
Reputation points
Hello, may I know why this .cmd file displays this error while trying to run this file? Here is the code:
@echo off
rem This is only a primitive and incomplete check for the location of the script - be careful !
IF /I EXIST "..\..\..\..\..\RailWorks.exe" (
echo "RW found. - All OK."
) ELSE (
echo Execute this script only in Content\Routes\--Routefolder--\Scenery\ !
echo You have started this script in %~dp0
)
echo %~dp0
if NOT EXIST OLD (
md old
move *.xml old\
)
cd old
echo %~dp0
pause
rem We create this list-file only once - so you can edit list-xml.txt later and run the script with another set of files again.
if NOT EXIST list-xml.txt (
dir /B *.xml > list-xml.txt
)
Setlocal EnableDelayedExpansion
for /f "eol=# delims==" %%i IN ( list-xml.txt ) DO (
set MyFile=%%i
IF NOT EXIST "!MyFile!" (
echo "Not found: !MyFile!" >> error.log
) ELSE (
powershell -Command "(gc "!MyFile!") -replace '\>HiLineAssets\\', '>' | Out-File -encoding ASCII "..\!MyFile!" "
echo !MyFile! processed.
)
)
)
if EXIST error.log (
echo There was an error - check error.log please.
)
cd ..
echo.
pause
3 answers
Sort by: Most helpful
-
Lukas Valancauskas 5 Reputation points
2023-04-12T15:44:38.7566667+00:00 -
MotoX80 35,706 Reputation points
2023-04-12T16:32:32.9166667+00:00 Check the encoding. Edit the cmd file with Notepad and verify that it shows "Windows (CRLF) UTF-8" in the lower right corner of the window. If it's something else use the file saveas dialog to set the encoding. Then from the command prompt, use the TYPE command to display the file contents. Does it look ok?
-
Rich Matheisen 47,856 Reputation points
2023-04-12T22:40:53.0233333+00:00 The quoting on this line in your .bat file isn't right:
powershell -Command "(gc "!MyFile!") -replace '\>HiLineAssets\\', '>' | Out-File -encoding ASCII "..\!MyFile!" "
Try replacing it with this:
powershell -Command "(gc '!MyFile!') -replace '\>HiLineAssets\\', '>' | Out-File -encoding ASCII '..\!MyFile!' "