Thanks in advance.
@Echo Off
SetLocal EnableDelayedExpansion
::Script to input text from a text file, and check each line to see if it starts "curPath: "
::Once the "curPath: " line has been identified, save it to a variable
Set _InputFile=F:\Locations.txt
for /f "tokens=* delims= " %%a in (%_InputFile%) do (
set /a N+=1
set v!N!=%%a
set vPath=!v!N!
::Remove the first 9 characters of the text line and check if it starts "curPath: "
if %vPath:~9% == "curPath: "
varPath == vPath
)
::Trim the path
set varPath=%varPath:curPath: =%
::echo %varPath%
IF "%varPath"=="Path1" set appPath="C:\Path1.py"
IF "%varPath"=="Path2" set appPath="C:\Path1.py"
IF "%varPath"=="Path3" set appPath="C:\Path1.py"
IF "%varPath"=="Path4" set appPath="C:\Path1.py"
start "" "%appPath%"
Can someone suggest why this script is failing?
Moderator: DosItHelp
Re: Can someone suggest why this script is failing?
'
You've got so many things wrong that I just eliminated the most obvious errors, there are more less obvious ones I'm sure.
Why do you enable delayed and then not use it ??
Your coding is very illogical, confusing... I rarely see such bad coding !
Maybe copy the dostips functions or mine, you may learn something.
Dostips functions
http://www.dostips.com/
ED's functions
viewtopic.php?f=3&t=1893&start=0
I've noticed you use a leading underscore when defining a variable.
In many languages the leading underscore means that the variable is globally available and is read-only, not to be written to by the programmer. Or even worse, that it is a build-in function. That could cause confusion, when mastering other langs.
Like marijuana I see DOS as a gateway drug
But there are other leading chars available to choose from when identifying a var.
I think the larger part of this community uses $ to represent variables as it is often used in other langs like so.
You've got so many things wrong that I just eliminated the most obvious errors, there are more less obvious ones I'm sure.
Code: Select all
@Echo Off &SetLocal EnableDelayedExpansion
::Script to input text from a text file, and check each line to see if it starts "curPath: "
::Once the "curPath: " line has been identified, save it to a variable
Set "_InputFile=F:\Locations.txt"
for /f "tokens=* delims= " %%! in (
"!_InputFile!"
) do (
set /a N += 1
set "v!N!=%%!"
"set vPath=!v!N!"
::Remove the first 9 characters of the text line and check if it starts "curPath: "
if /i ["!vPath:~9!"] == ["curPath: "] (
::
set "varPath=!vPath!"
)
)
::Trim the path
set "varPath=!varPath:curPath: =!"
::echo %varPath%
set /a $error = 1
for /l %%! in (
1, 1, 4
) do if /i ["!varPath!"] == ["Path%%~!"] (
::
set /a $error = 0
)
if !$error! equ 0 (
::
set appPath="C:\Path1.py"
start "" "!appPath!"
)
Your coding is very illogical, confusing... I rarely see such bad coding !
Maybe copy the dostips functions or mine, you may learn something.
Dostips functions
http://www.dostips.com/
ED's functions
viewtopic.php?f=3&t=1893&start=0
I've noticed you use a leading underscore when defining a variable.
In many languages the leading underscore means that the variable is globally available and is read-only, not to be written to by the programmer. Or even worse, that it is a build-in function. That could cause confusion, when mastering other langs.
Like marijuana I see DOS as a gateway drug
But there are other leading chars available to choose from when identifying a var.
I think the larger part of this community uses $ to represent variables as it is often used in other langs like so.