Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Current  Directory

Posted on 1998-12-15
5
Medium Priority
?
252 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

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

610 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