Public Group

# Current Directory?

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

## 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 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 == '\\' )		{				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 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 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 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 on other sites
Correct.

and its not a problem i just thought i would give you a heads up so you could get better answers :)

##### Share on other sites
the current directory is "."

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002299
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!