Solved How Do I Check If a Program is in the Execution Path?

Dell / DIMENSION 2400
February 5, 2012 at 01:05:34
Specs: MS-DOS 7.10, Pentium 4 / 1GB
I need to do this from an MS-DOS 7.10 boot floppy. I'm thinking something like:

SET Found=FALSE
FOR %%i IN (%PATH%) DO IF EXIST %%i\MYPROG.EXE SET Found=TRUE
IF '%Found%' == 'FALSE'                                                 GOTO ERRMSGnn

I haven't tested this yet, but is there a better more direct way?


See More: How Do I Check If a Program is in the Execution Path?

Report •


#1
February 5, 2012 at 03:34:18
✔ Best Answer
Under MS DOS 7.1 I can't suggest a better way, just code

SET Found=FALSE
FOR %%i IN (%PATH%) DO IF EXIST %%i.\MYPROG.EXE SET Found=TRUE
IF "%Found%"=="FALSE" ...

where %%i. takes care of paths like C:\ while working fine with no backslash suffixed ones too and avoid spaces around == in IF statement (use double quotes to embrace members).

Report •

#2
February 5, 2012 at 17:46:52
That's what I expected. Thanks for the tip about using the dot.

Do you have an example of how the single quote or spaces could cause a problem? I've seen it both ways, and in more confusing ways too. I remember reading long ago that one was superior to the other but can't remember where or why.


Report •

#3
February 6, 2012 at 07:40:24
Double quotes are THE RULE for IF statement and should always be coded even if their occurrence seems not requested. The ' may lead to error if the variable/string after expanded contains a quote (rare but not impossible, e.g. Joe's_Report.doc).

To avoid spaces before and after == (or = in SET) is THE RULE too since again spaces may cause mismatch when strings have leading or trailing blanks.


Report •

Related Solutions

#4
February 20, 2012 at 21:24:44
IVO,

Thanks for the good answers!


Report •


Ask Question