Current directory of the current process 
Author Message
 Current directory of the current process

Hello,

I am trying to get the current directory of the executable program
that is running. I tried using _getcwd() and GetCurrentDirectory()
neither of these functions returned the actual directory where
the executable is located. Both functions returned the same result which I
think is the working directory and not the actual directory where
the program is located.

TIA
Jacques



Mon, 07 Jul 2003 12:11:37 GMT  
 Current directory of the current process
On Wed, 17 Jan 2001 20:11:37 -0800, "Jacques Cooper"

Quote:

>I am trying to get the current directory of the executable program
>that is running. I tried using _getcwd() and GetCurrentDirectory()
>neither of these functions returned the actual directory where
>the executable is located. Both functions returned the same result which I
>think is the working directory and not the actual directory where
>the program is located.

Assuming you use MFC (otherwise it's still similar):

TCHAR szBuff[MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szBuff,
        MAX_PATH));

The buffer will contain the full path to the EXE, including filename
so you'll need to get rid of everything past the last backslash to get
the directory :)



Mon, 07 Jul 2003 13:26:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Changing current directory and getting directory name

2. Get the path of the current directory and system directory

3. Searching sub-directories of current directory

4. Default INI to current directory, not Windows directory

5. How to debug a process launched by current process

6. Suspending current process until spawned process finishes

7. getting process ID of the current process

8. Accessing current Profile Directory

9. Help - Get Current Directory from csharp.asmx

10. How do know how many *.txt files in current directory using C

11. How to get current directory in aspx page?

12. Getting current (stored not executed) directory

 

 
Powered by phpBB® Forum Software