🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6776

Re: Retrieving the Start from directory

#6776
From: Marc
Date: Wed, 20 Apr 2005 22:24
70 lines
3171 bytes
Hi

Thanks for your prompt response.

I tried your code and as I stated before it returns the 
Application path, as epected.

If I have a batch file on my desktop I want my application to 
return the location of my desktop. If I am located on a 
network path (\\Some Computer\SomeDirectory\Somefile.bat) I 
want to retrieve the \\Some Computer\SomeDirectory.  
GetModuleFileName returns the location of the EXE (C:\Program 
files...).  In both case the batch file run c:\Program files ...). 

Hopefully my question is clearer.

Thanks for your time
Marc




"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Marc" <bukwheat_NS@axess.com> wrote in message
>news:4266bf60@newsgroups.borland.com...
>
>> I am having an issue with retrieving the directory from
>> where my application is started from, let me explain...
>
>That is because you are making assumptions that you should not be making.
>
>> GetModuleFileName and GetCurrentDirectory aren't cutting it for
>> me.
>
>GetModuleFileName() works fine, you just have to strip off the FileName
>portion after calling it.  The TApplication::ExeName property uses
>GetModuleFileName().  You can use the VCL's ExtractFilePath() function to
>remove the filename from the returned value:
>
>    AnsiString folder = ExtractFilePath(Application->ExeName);
>
>Or, if you don't want to use the VCL, then just place a '\0' character after
>the last '\\' character in the string buffer that you pass to
>GetModuleFileName():
>
>    char folder[MAX_PATH+1] = {0};
>
>    DWORD dwCount = GetModuleFileName(NULL, folder, MAX_PATH);
>    for(DWORD dw = dwCount; dw > 0; --dw)
>    {
>        if( folder[dw-1] == '\\' )
>        {
>            folder[dw] = '\0';
>            break;
>    }
>
>As for GetCurrentDirectory(), that returns the calling process's current
>working directory, which can (and usually does) change dynamically (even
>multiple times) during the process's lifetime.  You should not rely on the
>current working directory at all to determine the folder the application is
>executed from.  You cannot even rely on it as the first call in WinMain(),
>as the current working directory can be set to a different folder by a
>shortcut that is launching the application, before WinMain() is even called.
>
>
>Gambit
>
>
Technical Details
Message-ID: <4266c896$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4266bf60@newsgroups.borland.com> <4266c43b@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d14a13f082d61e40
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Marc" <bukwheat_NS@axess.com>
Sender: "Marc" <bukwheat_NS@axess.com>
Reply-To: "Marc" <bukwheat_NS@axess.com>
Subject: Re: Retrieving the Start from directory
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 138.11.254.204     
X-Forwarded-For: unknown
References: <4266bf60@newsgroups.borland.com> <4266c43b@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4266c896$1@newsgroups.borland.com>
Date: 20 Apr 2005 14:24:38 -0800
X-Trace: newsgroups.borland.com 1114032278 207.105.83.66 (20 Apr 2005 14:24:38 -0800)
Lines: 71
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail