My Documents folder location

Feb 26, 2014 at 10:51am
I want to get the path of My Documents Folder in the vaiable MY_DOCUMENTS

char MY_DOCUMENTS[60];

Any help?
Feb 26, 2014 at 11:05am
1) This is Windows-specific, so really belongs in the Windows Programming forum.

2) Have a look at http://lmgtfy.com/?q=How+to+get+path+to+My+Documents
Feb 26, 2014 at 11:14am
Feb 26, 2014 at 11:22am
I've already tried that. But I was unsuccessful.
Can anyone please provide a code fragment in which My document location store in "MY_DOCUMENTS"

Please help
Feb 26, 2014 at 2:20pm
I've already tried that. But I was unsuccessful.

You're joking, right?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <Windows.h>
#include <ShellAPI.h>
#include <KnownFolders.h>
#include <ShlObj.h>

int main()
{
	CoInitialize(NULL);

	TCHAR* path = 0;
	SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, NULL, &path);
	CoTaskMemFree(path);

	return 0;
}
Last edited on Feb 26, 2014 at 3:07pm
Feb 27, 2014 at 11:28am
I want to save file using file handling in My documents folder and make new directories in My documents folder

But in every one's PC this address is different, depends upon his username and in which drive has he installed windows (C,D,E or other)

In above program the address is stored in "path" but how can I use it to make directory(_mkdir()) and save file
Feb 27, 2014 at 1:50pm
Lookup calls:
CreateDirectory
CreateFile (or use ofstream)
Feb 27, 2014 at 1:55pm
1
2
3
4
5
6
char dir[50] = { "C:\\Users\\User\\Documents\\save.dat" };
ofstream A;
A.open(dir);
.
.
.


I know this will work for me
But in everyone's PC this address is different

like you provided the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <Windows.h>
#include <ShellAPI.h>
#include <KnownFolders.h>
#include <ShlObj.h>

int main()
{
	CoInitialize(NULL);

	TCHAR* path = 0;
	SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, NULL, &path);
	CoTaskMemFree(path);

	return 0;
}



But how to get path to My documents in "dir"
Last edited on Feb 27, 2014 at 2:00pm
Feb 27, 2014 at 2:15pm
Really? You can't look up how to copy a string from one array to another?
Feb 27, 2014 at 3:05pm
I believe the below might give you another hint.

%USERPROFILE%\Documents

This will direct you to the user's documents
Feb 28, 2014 at 6:11pm
That assumes the documents folder is called "Documents" under the home directory.

It can be mapped elsewhere by sysadmins.
Last edited on Feb 28, 2014 at 6:12pm
Topic archived. No new replies allowed.