2
显然,我的桌面不是只读的,但stat()和findfirst()函数报告这是不可写的。我应该使用其他功能吗?为什么?C stat()函数报告Windows桌面文件夹是只读的
#include <iostream>
#include <ShlObj.h>
#include <sys/stat.h>
int main() {
PWSTR ppszPath;
if (::SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &ppszPath)==S_OK) {
std::wcout << L"Desktop folder: " << ppszPath << L"\n";
struct _stat64 buf;
if (_wstat64(ppszPath, &buf)==0) {
std::wcout << L"Writable: " << ((buf.st_mode & _S_IWRITE) != 0? "yes": "no") << L"\n";
}
}
}
这打印出的Windows7上64:
Desktop folder: C:\Users\heldepn\Desktop
Writable: no
谢谢,我希望能够在stat()的文档中找到这个信息,因为这偏离了相应的Posix行为,但显然这太需要了。 – Paavo
Windows安全模型比Posix更复杂,因此任何映射都不完整。 'stat'函数是非常懒惰的,只是使用文件属性。 –
一个小的澄清:只读标志不完全是装饰性的,它确实会阻止目录被删除。 –