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

Score
0
Vote Up
February 5, 2012 at 01:05:34 Pacific
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?


Jump to Best Answer ↓   Report •


#1
Vote Down
Score
0
Vote Up
February 5, 2012 at 03:34:18 Pacific

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).

Reply ↓  Report •

#2
Vote Down
Score
0
Vote Up
February 5, 2012 at 17:46:52 Pacific

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.


Reply ↓  Report •

#3
Vote Down
Score
1
Vote Up
February 6, 2012 at 07:40:24 Pacific

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.


Reply ↓  Report •

#4
Vote Down
Score
0
Vote Up
February 20, 2012 at 21:24:44 Pacific

IVO,

Thanks for the good answers!


Reply ↓  Report •

Reply to Message Icon Start New Discussion
Related Posts

« [Solved] Use a batch file to renam... [Solved] Read txt files through ba... »