Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!emcard!wa4mei!kd4nc!npiatl!dkelly From: dkelly@npiatl.UUCP (Dwight Kelly) Newsgroups: comp.sys.ibm.pc Subject: Re: Finding a program's path. Message-ID: <419@npiatl.UUCP> Date: 10 Aug 89 22:56:41 GMT References: <7207@ecsvax.UUCP> <36047@bu-cs.BU.EDU> <13343@siemens.siemens.com> Reply-To: dkelly@npiatl.UUCP (Dwight Kelly) Organization: Network Publications, Inc. Atlanta, GA Lines: 39 In article <13343@siemens.siemens.com> jrv@demon.siemens.com (James R Vallino) writes: >In article <36047@bu-cs.BU.EDU> madd@bu-it.bu.edu (Jim Frost) writes: >>In article <7207@ecsvax.UUCP> harris@ecsvax.UUCP (Mark Harris) writes: >>|I am writing a program which needs to know the path through which >>|it was loaded (rather than the current working directory). DOS >>|3.x puts this path in the environment, but DOS 2.x doesn't. Is >>|there a reasonably simple way to find this path in DOS 2.x? >> >>No. One way to do it is to compile the name of the program in and run >>a path search until you find it. Unfortunately if you rename the >>program > > this is a problem > >>or if you give an absolute path (either to override the path >>or to get to an executable which is not on the path) > > not a problem because if I remember correctly back to the dark ages DOS >2.x would not let you specify an absolute path to an executable. > Generally I do the following: 1) if Dos3.x, get the path out of argv[0] 2) if Dos2.x, do each of the following in order until you find the program. a) look in the current directory. b) following the PATH, looking for the program c) choose one of the following: c1) ask the user for the path c2) scan all directories for the program c3) store a configuration file somewhere that contains the path c4) dump core -- Dwight Kelly UUCP: gatech!npiatl!dkelly Director R&D AT&T: (404) 962-7220 Network Publications, Inc 2 Pamplin Drive Lawrenceville, GA 30245 Publisher of "The Real Estate Book" nationwide!