明らかに、私のデスクトップは読み取り専用ではありませんが、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