Article View: borland.public.cppbuilder.nativeapi
Article #17601Re: How to get application's directory?
From: Rodolfo Frino - Stargate Softwar...
Date: Sat, 22 Mar 2003 14:30
Date: Sat, 22 Mar 2003 14:30
47 lines
2390 bytes
2390 bytes
GetCurrentDirectory() should be called before changing the
Current Directory (I forgot to mention that) like that
ApplicationDirectory = Get_CurrentDirectory();
only once. Where Get_CurrentDirectory() is a wrapper.
around the GetCurrentDirectory() API
For example:
AnsiString ApplicationDirectory;
AnsiString Get_CurrentDirectory()
{
const DWORD BUFF_SIZE = 256;
char Buffer[BUFF_SIZE];
GetCurrentDirectory(BUFF_SIZE, Buffer); //Win 32 API
return AnsiString(Buffer);
}
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// Be Careful since SetCurrentDirectory() can change the
// Current Directory.
ApplicationDirectory = Get_CurrentDirectory();
//...
SetCurrentDirectory("C:\\TEMP");
//...
}
Of course SetCurrentDirectory("C:\\TEMP");
could be called later during the application's lifetime.
And, of course, you don't have to call
ApplicationDirectory = Get_CurrentDirectory();
again, but you can call
String SomethingElse = Get_CurrentDirectory();
if you needed to.
Rodolfo
> Usin GetCurrentDirectory is not to be recommended as the user can change
> what the current directory is when the application starts. If they do then
> this method does not work.
Technical Details
Message-ID:
<3e7c7c8c@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e7a7800$1@newsgroups.borland.com> <3e7a8e39@newsgroups.borland.com> <3e7ae7af$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,440cb76ba9be739c X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-23 23:31:23 PST From: "Rodolfo Frino - Stargate Software" <starcinema@eftel.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e7a7800$1@newsgroups.borland.com> <3e7a8e39@newsgroups.borland.com> <3e7ae7af$1@newsgroups.borland.com> Subject: Re: How to get application's directory? Date: Sun, 23 Mar 2003 01:30:37 +1100 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 203.129.132.87 Message-ID: <3e7c7c8c@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1048345740 203.129.132.87 (22 Mar 2003 07:09:00 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail