Solved

Current  Directory

Posted on 1998-12-15
5
249 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 30 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

691 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