PDA

Click to See Complete Forum and Search --> : Retrieving current dir


Zvonko
Sep 16th, 2000, 05:56 AM
Hello!

How can I retrieve current dir (where my EXE is placed, like in vb App.Path)?
And which are alternatives of Left() and Right() VB function in VC++?

parksie
Sep 16th, 2000, 09:26 AM
When you start a console app (using main), argv[0] contains the full path and filename of your executable, for example c:\myprog\myprogram.exe.
To use equivalents of Left and Right, simply use strncpy in this way:

char *pcSrc = "Hello World";
char *pcDest = new char[length+1];
strncpy(pcDest, pcSrc+offset, length);
pcDest[length] = 0; // Terminator

This code reproduces Left. To use Right, you'd have to count backwards from the end of the string.

Zvonko
Sep 16th, 2000, 09:47 AM
I'm developing a MFC app.
Is argv[0] the same in MFC as in console app or do I have to do something else?

Yonatan
Sep 16th, 2000, 11:05 AM
You can use the GetCurrentDirectory function in Win32/MFC apps.

TCHAR tcCurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH, tcCurDir);
// tcCurDir now contains the current directory.
// At least, it should be. :rolleyes: