Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFC: GetCurrentDirectory function

Tags:

mfc

I know that GetCurrentDirectory() and SetCurrentDirectory() functions exist on the MFC framework, but I don't have a CFtpConnection object in my application. I have a simple CWinApp-derived class, and I would like to retrieve its working directory upon program startup. What's the easiest method to achieve this goal? Thanks in advance for the advices.

like image 701
stanigator Avatar asked Jun 17 '09 23:06

stanigator


People also ask

What is Java working directory?

The current working directory means the root folder of your current Java project.


2 Answers

GetCurrentDirectory is a simple Win32 API function, so just call it like this:

TCHAR currentDir[MAX_PATH];
GetCurrentDirectory( MAX_PATH, currentDir );
like image 125
Gerald Avatar answered Sep 19 '22 07:09

Gerald


I assume you are trying to get the directory where your .exe file is located instead of the current directory. This directory can be different from the current directory.

    TCHAR buff[MAX_PATH];
    memset(buff, 0, MAX_PATH);
    ::GetModuleFileName(NULL,buff,sizeof(buff));    
    CString strFolder = buff;
    strFolder = strFolder.Left(strFolder.ReverseFind(_T('\\'))+1);    
like image 36
www.diwatu.com Avatar answered Sep 21 '22 07:09

www.diwatu.com