delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/03/13:05:54

From: johan AT technologist DOT com (Johan Levin)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Determining the path of the executable at runtime
Date: 3 Sep 1997 15:02:59 GMT
Organization: -
Lines: 37
Message-ID: <5uju73$i3n@mn5.swip.net>
References: <927cd$11e31 DOT 3dd AT news DOT eznet DOT net> <01bcb82c$cf0ae200$638562cf AT damien>
NNTP-Posting-Host: 130.244.152.220
Mime-Version: 1.0
NNTP-Posting-User: s-49839
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <01bcb82c$cf0ae200$638562cf AT damien>, damien@%poe.org says...
>
>Karl Garrison <karlos AT eznet DOT net> wrote in article
><927cd$11e31 DOT 3dd AT news DOT eznet DOT net>...
>> I am making a HTML editor that will look for configuration files and the
>> like in the same directory as the executable.  I don't want to force the
>> user to install in a particular directory, or make them add enviroment
>> variables to their autoexec.bat.

>It sounds to me like the only reason you want the path the program is in is
>to find the config files.  Is that correct?  If so, all you need to do is
>open the file with only the file name.  That way it will look in the
>current directory, which should be the one your program is in.

The executable *can* be run from a different directory.
(ex if you type: "\html\html.exe" or if the executable is in the dos' PATH.)

To find the real directory of the executable look at argument argv[0] that
is passed to the program.

This little program will print the entire path of the executable (including
filename):

void main(int argc, char **argv)
{
	puts(argv[0]);
}

To find the config-file all you have to do is to split the path, exchange
the filename and merge it again.

-- 
Johan Levin                         Sweden
------------------------------------------
homepage: http://home2.swipnet.se/~w-21572
mail    : johan AT technologist DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019