Board index » delphi » Easy question (I think!)

Easy question (I think!)

Hello all..
  I wish to be able to determine within my program's code, which
directory my program resides in. In other words, if I have my program in
C:\TEMP and am running it from that directory, is there a command in
Delphi that will return that directory, ie. C:\TEMP.
  The reason for all this is that I want to create some output files and
have them written to the same directory that my program resides in.

   All and any help is most appreciated!

Cheers,
  Shawn Halfpenny
  az...@auracom.com

 

Re:Easy question (I think!)


Use ExtractFilePath(Application.Exename)

--
Willy Speeckaert
 S. D. S. (Speeckaert Database Systems)
 WEB page: http://www.total.net/~willys/
    email: wil...@total.net

Re:Easy question (I think!)


Quote
>   I wish to be able to determine within my program's code, which
> directory my program resides in. In other words, if I have my program in
> C:\TEMP and am running it from that directory, is there a command in
> Delphi that will return that directory, ie. C:\TEMP.
>   The reason for all this is that I want to create some output files and
> have them written to the same directory that my program resides in.

Someone gave me this: ExtractFileDir(paramstr(0));
But I think that ExtractFileDir(Application.Exename); is much nicer to look
at :-)

--
Brian Pedersen, System Specialist, Alta Copenhagen
http://www.alta.dk
Personal homepage:
http://home6.inet.tele.dk/brianp

Get PR-Tracker -- tracks problem reports, defects, bugs
INFORMATION:  http://www.prtracker.com/info.html
DOWNLOAD:     http://www.prtracker.com/download.html

Re:Easy question (I think!)


Check the File functions in Delphi, I think  there is something like
ExtractFilePath and ExtractFilename

Shawn Halfpenny <az...@auracom.com> wrote in article
<5sgntg$4p...@storm.cycor.ca>...

Quote
> Hello all..
>   I wish to be able to determine within my program's code, which
> directory my program resides in. In other words, if I have my program in
> C:\TEMP and am running it from that directory, is there a command in
> Delphi that will return that directory, ie. C:\TEMP.
>   The reason for all this is that I want to create some output files and
> have them written to the same directory that my program resides in.

>    All and any help is most appreciated!

> Cheers,
>   Shawn Halfpenny
>   az...@auracom.com

Re:Easy question (I think!)


In article <01bca942$52dcf7c0$882b7ba0@00008320c07d>,
   "Lucian" <xy10...@exchange.oldmutual.com> wrote:

Quote
>Check the File functions in Delphi, I think  there is something like
>ExtractFilePath and ExtractFilename

Yep, that's pretty close:

  ExtractFileDir(Application.ExeName) will do it

Quote
>Shawn Halfpenny <az...@auracom.com> wrote in article
><5sgntg$4p...@storm.cycor.ca>...
>> Hello all..
>>   I wish to be able to determine within my program's code, which
>> directory my program resides in. In other words, if I have my program
>> in C:\TEMP and am running it from that directory, is there a command
>> in Delphi that will return that directory, ie. C:\TEMP.

  --=- Ritchie Annand

Re:Easy question (I think!)


Shawn Halfpenny wrote in article <5sgntg$4p...@storm.cycor.ca>...

Quote
>Hello all..
>  I wish to be able to determine within my program's code, which
>directory my program resides in. In other words, if I have my program in
>C:\TEMP and am running it from that directory, is there a command in
>Delphi that will return that directory, ie. C:\TEMP.
>  The reason for all this is that I want to create some output files and
>have them written to the same directory that my program resides in.

>   All and any help is most appreciated!

>Cheers,
>  Shawn Halfpenny
>  az...@auracom.com

 You can use the following function:

Function RunDir:String;
  { This function returns the Directory your application
    is ran from which includes the final '\' }
var
  St : String;
Begin
  St := ParamStr(0);
  While St[Length(St)] <> '\' do
    Delete(St, Length(St), 1);
  RunDir := St;
End;

I know there is a function for extracting the directory from a file path,
but it is different between Delphi 16 bit and 32 bit.   This works on both
versions.

------------------------------------------------------
Donald Johnson                     bin...@computerbargain.com
Binary Engineers                                   Software Developer
http://www.computerbargain.com/binary

Re:Easy question (I think!)


Quote
> > Hello all..
> >   I wish to be able to determine within my program's code, which
> > directory my program resides in. In other words, if I have my
> program in

Take a look at paramstr(0)

Re:Easy question (I think!)


ExtractFilePath(Aplication.Exename) is another option

In article <33FC68C2.9B72C...@xs4all.nl>, Stefan Prins
<stefa...@xs4all.nl> writes

Quote
>> > Hello all..
>> >   I wish to be able to determine within my program's code, which
>> > directory my program resides in. In other words, if I have my
>> program in

>Take a look at paramstr(0)

Kind Regards
Claire

Other Threads