Mail Archives: djgpp/1997/09/03/13:05:54
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 -