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'函數是非常懶惰的,只是使用文件屬性。 –
一個小的澄清:只讀標誌不完全是裝飾性的,它確實會阻止目錄被刪除。 –