Board index » delphi » Finding the directory that a program has been run from

Finding the directory that a program has been run from

How would you find the directory that a program has been run from?

This seems very difficult because FSearch only searches in a given directory
and there are no DOS commands to do this. I am not sure about other Pascal
functions such as GetEnv although.

Thanks for reading this message and for any help you give.

Andrew.

 

Re:Finding the directory that a program has been run from


Quote
Andrew Turing <bhc.tril...@{*word*269}.net> wrote in message

news:rJGI4.4765$hh6.139462@news2-win.server.ntlworld.com...

Quote
> How would you find the directory that a program has been run from?

> This seems very difficult because FSearch only searches in a given
directory
> and there are no DOS commands to do this. I am not sure about other Pascal
> functions such as GetEnv although.

> Thanks for reading this message and for any help you give.

ParamStr(0) gives you the name of the .EXE, including the path. strip the
progname.exe off the end of it with fsplit and there you are!

Doesn't work on really old DOS versions (<3.1 if memory serves). I think I
recall mention of some complications when the program is run under the IDE,
for some versions of the IDE, but I haven't seen that one myself.

FP

Re:Finding the directory that a program has been run from


In article <8cveeg$aa...@kermit.esat.net>,

Quote
Frank Peelo <fpe...@indigo.ie> wrote:

>Doesn't work on really old DOS versions (<3.1 if memory serves).

That is it requires at least 3.0. Dos 2.x did not support that.

Quote
> I think I
>recall mention of some complications when the program is run under the IDE,
>for some versions of the IDE, but I haven't seen that one myself.

If you compile to memory, then that produces the name if the IDE. That
is IMO pretty dangerous as it could lead to accidental tampering with
the TURBO.EXE.

Osmo

Re:Finding the directory that a program has been run from


On Tue, 11 Apr 2000 15:29:54 +0100, "Andrew Turing"

Quote
<bhc.tril...@{*word*269}.net> wrote:
>How would you find the directory that a program has been run from?

Please formulate your question more precisely:

If you want the directory where the executed program is located as
file, then paramstr(0) [under the appropriate DOS version] will give
an answer.

If you want to know the directory from which the program is executed,
i.e. the current DOS directory, then FExpand('') will be an answer.

Hope that helps

Wolfgang

--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header.

Re:Finding the directory that a program has been run from


Quote
>In article <8cveeg$aa...@kermit.esat.net>,
>Frank Peelo <fpe...@indigo.ie> wrote:

>>Doesn't work on really old DOS versions (<3.1 if memory serves).

>That is it requires at least 3.0. Dos 2.x did not support that.

Do you know more about a DOS version greater than 3.0 and less than
3.1? What are the differences to 3.0 or 3.1?
--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header.

Re:Finding the directory that a program has been run from


In article <38f389dc.6520...@news.munich.netsurf.de>,

Quote
Wolfgang Ehrhardt <Wolfgang.Ehrhardt.PLEASE.REM...@munich.netsurf.de> wrote:

>>In article <8cveeg$aa...@kermit.esat.net>,
>>Frank Peelo <fpe...@indigo.ie> wrote:

>>>Doesn't work on really old DOS versions (<3.1 if memory serves).

>>That is it requires at least 3.0. Dos 2.x did not support that.

>Do you know more about a DOS version greater than 3.0 and less than
>3.1? What are the differences to 3.0 or 3.1?

3.0 was filled with bugs.

Osmo

Re:Finding the directory that a program has been run from


"Andrew Turing"  wrote in a message to All:

 "T> From: "Andrew Turing" <bhc.tril...@{*word*269}.net>
 "T> Subject: Finding the directory that a program has been run from

 "T> How would you find the directory that a program has been run from?

ParamStr(0) will give you the complete path of the program i.e.
c:\util\myprogram.exe

Well in TP, I think BP and certainly in FPC.
Just take the string, look for the last '\' chop off everything after
that and you have the directory.

--
| Return Address:      Frank.McCorm...@819.m-net.axess.com
| Standard disclaimer: The views of this user are strictly her/his own.
|                      From addresses mangled solely to block spamming.
| Apologies to those wishing to respond, change m-net to mnet.
| Signature auto-added at gateway.

Re:Finding the directory that a program has been run from


Thanks All.

Andrew

Re:Finding the directory that a program has been run from


On 11 Apr 2000 21:32:27 +0300, ronka...@cc.helsinki.fi (Osmo Ronkanen)
wrote:

Quote
>In article <8cveeg$aa...@kermit.esat.net>,
>Frank Peelo <fpe...@indigo.ie> wrote:

>>Doesn't work on really old DOS versions (<3.1 if memory serves).

>That is it requires at least 3.0. Dos 2.x did not support that.

Does 3.0 support it? I thought you needed 3.1.

FP

Re:Finding the directory that a program has been run from


After reading the info supplied in this thread I ran a test program on a Win98
LAN and found that I can make running my TP 7.0 programs in that environement
even easier.

Under Win98 (and probably NT) DOS programs don't have an automatic link to their
home directory. I was getting around this by passing the Path to my programs and
then using that info to make it possible to access files.

By extracting the Path from Paramstr(0) you can provide the info to the program
without having to pass it on the command line or through the Windows .PIF file.
This makes everything easier to do.

Quote
Frank Peelo wrote:
> Andrew Turing <bhc.tril...@{*word*269}.net> wrote in message
> news:rJGI4.4765$hh6.139462@news2-win.server.ntlworld.com...
> > How would you find the directory that a program has been run from?

> > This seems very difficult because FSearch only searches in a given
> directory
> > and there are no DOS commands to do this. I am not sure about other Pascal
> > functions such as GetEnv although.

> > Thanks for reading this message and for any help you give.

> ParamStr(0) gives you the name of the .EXE, including the path. strip the
> progname.exe off the end of it with fsplit and there you are!

> Doesn't work on really old DOS versions (<3.1 if memory serves). I think I
> recall mention of some complications when the program is run under the IDE,
> for some versions of the IDE, but I haven't seen that one myself.

> FP

--
Val Mehling - anti-spam in effect.
For e-mail reply to: va...@earthlink.net

http://home.earthlink.net/~valjm/
Anyone but{*word*151}for President

Other Threads