?
Solved

Current  Directory

Posted on 1998-12-15
5
Medium Priority
?
250 Views
Last Modified: 2010-08-05
Is there a string/function in VC++ 5
for getting the current directory that the app is running from?
0
Comment
Question by:atsui
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 90 total points
ID: 1180240
Yes. It is called 'GetCurrentDirectory()', the prototype is
DWORD GetCurrentDirectory( DWORD nBufferLength,
 // size, in characters, of directory buffer
 
LPTSTR lpBuffer
 // address of buffer for current directory
 
);
 



0
 
LVL 22

Expert Comment

by:nietod
ID: 1180241
>>  the current directory that the app is running from?
Those are two different things.  There is a current directory, that is the directory that is used by most commands when a file is specified without a path.   Seperate from that is the directory that the app is running from.  

Which do you want?  

jkr's answer is for the current directory, but if you want the directory that the app is running from use GetModuleFileName() and remove the name from the path returned.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1180242
That's right. 'GetCurrentDirectory()' retrieves the directory the application was started from of the one set by 'SetCurrentDirectory()' (both refer to the 'working directory'), whereas 'GetModuleFileName()' returns the path for the file used to create the calling process (maybe 8.3 format, use 'GetLongPathName()' to convert it).
0
 
LVL 1

Author Comment

by:atsui
ID: 1180243
So is this what I'm supposed to do to get the string?

      LPSTR curdir;
      GetCurrentDirectory(30,curdir);
      ShellExecute(NULL,"explore",*curdir,NULL,NULL,SW_SHOW)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1180244
Ooops, no - as 'LPSTR curdir' isn't initialized, the results are unpredictable...
Better try

char curdir[ MAX_PATH];
GetCurrentDirectory(MAX_PATH,curdir);
ShellExecute(NULL,"explore",curdir,NULL,NULL,SW_SHOW);

NOTE that i removed '*' from the last line ...

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question