Sign in to follow this  

Current Directory?

This topic is 4716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm working in C++ and I was wondering, how would I get the current directory? ( The directory that the program is being executed from ) Thank you for your help, -Lenox

Share this post


Link to post
Share on other sites
if u are doing a standard console program, the path of the current executable is in the command line as the first argument.

or



int i;
GetModuleFileName(NULL, &localPath[0], sizeof (localPath));

for( i = strlen(&localPath[0])-1 ; i >= 0 ; i-- )
{
if( localPath[i] == '\\' )
{
localPath[i+1]=NULL;
break;
}
}



the string localPath is just local to this code. I took this code from a class i wrote so it was cat class-scope.

ace

Share this post


Link to post
Share on other sites
I am not sure what OS you are working in, but I know that in windows/DOS, you can include direct.h and use the call

char *_getcwd( char *buffer, int maxlen );

Share this post


Link to post
Share on other sites
I guess the question here really is what exactly do you intend to do because if you are playing a wav file for instance and its in the same dir as your .cpp or exe then it would be like

char filetoplay[] = "mywav.wav";

if it is in the bob dir then it would look like this

char filetoplay[] = "bob\mywav.wav";

or

char filetoplay[] = "C:\programming\bob\mywav.wav";

but hey this may not even be what your talking about lol please try to be clearer with your descriptions and it will be easyer to get help :P

Share this post


Link to post
Share on other sites
Ah, so if I just do "Blah.wav," it automatically assumes that Blah.wav is in the executable's (or .dll's) directory, unless specified like "Sounds\Blah.wav?"

(Sorry for not being very descriptive in the original post.)

[Edited by - Lenox on January 16, 2005 10:33:23 PM]

Share this post


Link to post
Share on other sites

This topic is 4716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this