Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_getcwd() 3

Status
Not open for further replies.

zigular

Technical User
Jun 29, 2004
18
DE
and again me..

to use the upper named method, which include do I need?

thanx a lot
hilmar
 
goto enter _getcwd into the search page and click on the most relevent search, probably the first one, i.e. (_getcwd, _wgetcwd (Visual C++ Libraries)) and scroll down to the example.
 
1. It's not a method, it's (non-standard;) library routine.
2. #include <direct.h>
3. It returns the current working directory on the current drive. It's NOT this exe module's directory!
 
OK, cool. I just came here to find out how you get the "exe module's directory", and the award winning ArkM probably knows, so you can kill another if you tell me what to call. It's always the simple things that cause the most watsed time.
 
Code:
#include <windows.h>
#include <cstring>
#include <string>

string GetMyPath()
{
  char path[MAX_PATH];
	
  if (GetModuleFileName(0,path,sizeof path))
  {
     char* p = strrchr(path,'\\');
     if (p)
        *p = 0; // or p[1] = 0 for trailing backslash...
  }
  else path[0] = 0; // Alas, a very strange error...
  return path;
}
Modify if you don't want C++ strings (it's freeware)...
Don't forget to pass path array into the func (w/o string).
Also a full exe path is in argv[0] (argv - the 2nd parm of the main()) - but it's not so robust method because of sometimes there is only module file name in argv[0] (it's the other story)...
 
And I thank you kindly, sir. Just what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top