DWORD d = GetFileAttributes(path.c_str());
根據返回的十進制,對比文件屬性,來檢索指定文件或目錄的文件系統屬性。
也可以使用
if ((d & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE)
來快速確定文件是否具有某一屬性
另外介紹下path.c_str()
語法:
const char *c_str();
c_str()函數返回一個指向正規C字符串的指針常量, 內容與本string串相同.
這是為了與c語言兼容,在c語言中沒有string類型,故必須通過string類對象的成員函數c_str()把string 對象轉換成c中的字符串樣式。
#include <Windows.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
std::string path;
path = "C:\\Users\\xxx\\OneDrive\\Documents\\1.docx";
cout << path << endl;
DWORD d = GetFileAttributes(path.c_str());
if ((d & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE)
{
// The file isn't available on local storage...
}
return 0;
}