Find path to a Folder (C++)

Started by
4 comments, last by Dan Caranfil 18 years, 1 month ago
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?
Advertisement
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
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,
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
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].
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
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!

This topic is closed to new replies.

Advertisement