Board index » delphi » What is, or how to set, the default file path?

What is, or how to set, the default file path?

What is the default file path when an app is launched?

For example, if the following code is in my FormCreate procedure, where
will ZAZA.TXT be created?

   AssignFile(f, 'ZAZA.TXT');
   Rewrite(f);
   Writeln(f,'Where did this get put?');
   CloseFile(f);

I had assumed that the default file path is always set to the location of
the app itself.  But I've run into situations where it is not -- for
example, it might be the last directory used in the IDE before the I did
an F9 (Run).

So,
  -- what is the default file path?
  -- how is it set?
  -- if I need to explicitly set the app's directory as my filepath, how
do I retrieve it?

Thanks,
Kevin

 

Re:What is, or how to set, the default file path?


Quote
Kevin C. Killion wrote in message ...
>   AssignFile(f, 'ZAZA.TXT');
>   Rewrite(f);
>   Writeln(f,'Where did this get put?');
>   CloseFile(f);

Hmm, what if you did Assignfile(F,'.\zaza.txt)?
I think the application itself (so not running under Delphi)
wil take the directory it is in.

Regards

Hertog

Re:What is, or how to set, the default file path?


ExtractFilePath is the function you would want to look at for determining
the directory of the application.

Quote
> I had assumed that the default file path is always set to the location of
> the app itself.  But I've run into situations where it is not -- for
> example, it might be the last directory used in the IDE before the I did
> an F9 (Run).

> So,
>   -- what is the default file path?
>   -- how is it set?
>   -- if I need to explicitly set the app's directory as my filepath, how
> do I retrieve it?

Re:What is, or how to set, the default file path?


AssignFile(F,extractfilepath(application.exename)+'zaza.txt');

application.exename holds the complete path and filename to the running
executable and extractfilepath does as it says. it takes the path, so
add your filename and you're done.

HTH

  Roel

Kevin C. Killion <ke...@shsmedia.com> wrote:

: What is the default file path when an app is launched?

: For example, if the following code is in my FormCreate procedure, where
: will ZAZA.TXT be created?

:    AssignFile(f, 'ZAZA.TXT');
:    Rewrite(f);
:    Writeln(f,'Where did this get put?');
:    CloseFile(f);

: I had assumed that the default file path is always set to the location of
: the app itself.  But I've run into situations where it is not -- for
: example, it might be the last directory used in the IDE before the I did
: an F9 (Run).

: So,
:   -- what is the default file path?
:   -- how is it set?
:   -- if I need to explicitly set the app's directory as my filepath, how
: do I retrieve it?

: Thanks,
: Kevin

Re:What is, or how to set, the default file path?


Quote
>   Roel Spapens <ro...@stack.nl> writes:
>  : I had assumed that the default file path is always set to the location of
>  : the app itself.  

I am not sure what you need to do. But there are things called GetCurrentDir and SetCurrentDir that you can use to get and set the dir that will be default when using
save/open dialogs etc.

And as was written earlier you can use extractfilepath(application.exename) to get the path to where the exe-file is but that is not necessarily the same as the default
directory when your program is launced. It can be launched with a setting for which directory to work in.

johan

Re:What is, or how to set, the default file path?


Quote
Kevin C. Killion wrote:

> What is the default file path when an app is launched?

>   -- if I need to explicitly set the app's directory as my filepath,  > how do I retrieve it?

> Thanks,
> Kevin

In Delphi 1, the GetDir procedure gets the current default directory,
and the ChDir procedure sets it.

--
Howard L. Kaplan
Psychopharmacology and Dependence Research Unit
Women's College Hospital
76 Grenville Street, 9'th floor
Toronto, Ontario
Canada  M5S 1B2
(416)323-6400, ext 4915
howard.kap...@utoronto.ca

Re:What is, or how to set, the default file path?


Quote
Howard Kaplan wrote:
> Kevin C. Killion wrote:

> > What is the default file path when an app is launched?

> >   -- if I need to explicitly set the app's directory as my filepath,  > how do I retrieve it?

> > Thanks,
> > Kevin

> In Delphi 1, the GetDir procedure gets the current default directory,
> and the ChDir procedure sets it.

But don't rely on it.  There are various functions which can change the
current path automagically (eg the Open dialog).  I also ran into an
expensive 3rd party component recently that messed up the current path.

I got into some trouble in this area in my first big Delphi app, and now
I always use full paths.  Be warned.

Andrew
--
Andrew Gabb
 email: ag...@tpgi.com.au
 phone: +61 8 8342-1021
   fax: +61 8 8269-3280
Technology Australasia's website is at http://www.taa.com.au
-----

Other Threads