Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hi, i have some old code from win2000 days

it uses this code
C#
if(!SHGetSpecialFolderLocation( 0, CSIDL_PERSONAL, &pidl ) ){
    if(SHGetPathFromIDList( pidl, path ) ){
        rootPath = path;
    }
}


to get the path to My Documents and has worked fine for a long time

now when i compile and run it, it returns the path 'C:\Users\steve\Documents'

however, a quick look in C:\Users\steve shows that the folder is called 'My Documents' (note, i'm on windows 7, standard installation as far as i can remember)

if i go to the start menu and select Documents, i get to Libraries\Documents which in reality is exactly the same place as 'C:\Users\steve\My Documents'

but at no point in any of this is does 'C:\Users\steve\Documents' seem to exist

this is a problem when i try to open a file with fopen with a path 'C:\Users\steve\Documents\myfile.txt' or whatever

interestingly, i have a file tree app that takes the root path the above code and it works file, it finds all the files

CFileFind finder; finder.FindFile( root+_T("*.*") );

so i'm very confused, i realize this is microsoft playing mind games with me, i'm just looking for a way to get a real path to the Documents folder


UPDATE:
Solved by OP himself - posted as one of the answers.
Posted
Updated 29-May-11 1:03am
v2

1 solution

ok, i figured it out

it seems that path i get from SHGetSpecialFolderLocation or 'C:\Users\steve\Documents' is the true path i guess. if if right click on the file myfile.txt and look at the properties, it says its in 'C:\Users\steve\Documents'

it also turns aout that fopen_s is working. in the question i said i was using fopen which was true before but i changed to fopen_s to avoid the depreciated warning on the compile what i didn't realize if the return from fopen_s is an enum

so
if(!fopen_s(&fp, lpszPathName, "r")) doesn't work

but
if(fopen_s(&fp, lpszPathName, "r") != 0) does work
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900