显然,我的桌面不是只读的,但是 stat() 和 findfirst() 函数将其报告为不可写。我应该改用其他功能吗?为什么?
#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 x64 上打印出来:
Desktop folder: C:\Users\heldepn\Desktop
Writable: no