Sign in to follow this  

Find path to a Folder (C++)

This topic is 4304 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

I want to make my game save the screenshots to a folder in 'MyPictures'. How do I make my program do this? I have an approximate idea how it should be done but, if posible, I would like not the reinvent the wheel. Does anyone have any tutorial on this?

Share this post


Link to post
Share on other sites
Hey Dan,

Are you looking for the code that will give you the folder in which the executable runs (so that you can locate the "MyPictures" directory relative to your executable)? If so, it is GetModuleFileName(GetModuleHandle(NULL), pszPath, MAX_PATH).

If you are looking for how to create files and directories, try a Google(TM) search. If you are looking for how to browse the content of a directory, try a Google(TM) search on FindFirstFile. And if you are looking for how to get a screenshot from your game, well... just be more specific please... :)
Cheers
StratBoy61

Share this post


Link to post
Share on other sites
MyPictures as well as a bunch of other path are dependant on the user name and a lot of other things. StratBoy61'is idea may be overkill (you may end up FindFirstFinling the whole hard drive, plus all the other if the user created multiple partictions). You can't even find it by using a relative path, because you don't know where it is in the first place. Moreover, MyPictures's name on a French WinXP is "Mes Images".

The only solution is to your problem is to use SHGetFolderPath


TCHAR szPath[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL,
CSIDL_MYPICTURES|CSIDL_FLAG_CREATE,
NULL,
0,
szPath)))
{
// do whatever you want sith szPath...
}


HTH,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
Moreover, MyPictures's name on a French WinXP is "Mes Images".

Ahhh... My Pictures, like My Documents ? Suis-je bete ! ;)
Sorry for that.
StratBoy61

Share this post


Link to post
Share on other sites
You may use shell's SHGetSpecialFolderPath () / SHGetFolderPath () functions. The most important parameter is the folder ID, which you can look up at MSDN.

[Edit]: I don't think I typed that slow [smile].

Share this post


Link to post
Share on other sites
Quote:

TCHAR szPath[MAX_PATH];

if(SUCCEEDED(SHGetFolderPath(NULL,

CSIDL_MYPICTURES|CSIDL_FLAG_CREATE,

NULL,

0,

szPath)))

{

// do whatever you want sith szPath...

}

Thats exactly what I was looking for, thanks so much!

Share this post


Link to post
Share on other sites

This topic is 4304 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