本文介绍了[已解决]在Windows 7(和Vista)上获取“我的文档"路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些来自win2000的旧代码

它使用此代码

i have some old code from win2000 days

it uses this code

if(!SHGetSpecialFolderLocation( 0, CSIDL_PERSONAL, &pidl ) ){
    if(SHGetPathFromIDList( pidl, path ) ){
        rootPath = path;
    }
}



以获得通往我的文档"的路径,并且已经运行了很长时间了

现在,当我编译并运行它时,它返回路径"C:\ Users \ steve \ Documents"

但是,对C:\ Users \ steve的快速浏览显示该文件夹称为我的文档"(请注意,据我所知,我在Windows 7上为标准安装)

如果我转到开始"菜单并选择文档",则会转到"Libraries \ Documents",实际上与"C:\ Users \ steve \ My Documents"完全相同

但是在任何情况下,似乎都不存在"C:\ Users \ steve \ Documents"

当我尝试使用路径为"C:\ Users \ steve \ Documents \ myfile.txt"或其他任何文件的fopen打开文件时,这是一个问题
有趣的是,我有一个文件树应用程序,它采用了上面代码的根路径,并且可以工作在文件中,可以找到所有文件

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

所以我很困惑,我意识到这是微软和我一起玩的智力游戏,我只是在寻找一种方法来获取Documents文件夹的真实路径


更新:
由OP自己解决-作为答案之一发布.



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.

推荐答案

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


但是


but

if(fopen_s(&fp, lpszPathName, "r") != 0) does work


这篇关于[已解决]在Windows 7(和Vista)上获取“我的文档"路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:46