获取、设置文件属性和时间
WIN32_FILE_ATTRIBUTE_DATA wfad;CString strPath = "SystemTestDlg.h";CString strInfo;ULONGLONG liFileSize;if(!GetFileAttributesEx(strPath,GetFileExInfoStandard,&wfad)){AfxMessageBox("Get File Attributes Error");return;}//Get file timem_ctrlDisplay.SetSel(-1,-1);strInfo.Format(_T("%s%s\r\n"),"Create File time:",ShowFileTime(&wfad.ftCreationTime));//wfad.ftLastAccessTime//wfad.ftLastWriteTimem_ctrlDisplay.ReplaceSel(strInfo);//Get file sizeliFileSize = wfad.nFileSizeHigh;liFileSize << sizeof(DWORD)*8;liFileSize += wfad.nFileSizeLow;m_ctrlDisplay.SetSel(-1,-1);strInfo.Format(_T("%s%I64u\r\n"),"File Size: ",liFileSize);m_ctrlDisplay.ReplaceSel(strInfo);//Get file attributesstrInfo = "";if(wfad.dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE){strInfo += "<Archive>";}if(wfad.dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED){strInfo += "<Compressed>";}//FILE_ATTRIBUTE_DIRECTORY//FILE_ATTRIBUTE_ENCRYPTED//FILE_ATTRIBUTE_HIDDEN//FILE_ATTRIBUTE_NORMAL//FILE_ATTRIBUTE_OFFLINE//FILE_ATTRIBUTE_READONLY//FILE_ATTRIBUTE_SPARSE_FILE//FILE_ATTRIBUTE_SYSTEM//FILE_ATTRIBUTE_TEMPORARYm_ctrlDisplay.SetSel(-1,-1);m_ctrlDisplay.ReplaceSel(strInfo + "\r\n");//Set file attributes//DWORD dwFileAttributes = GetFileAttributes(strPath);DWORD dwFileAttributes = wfad.dwFileAttributes;dwFileAttributes |= FILE_ATTRIBUTE_READONLY;if(SetFileAttributes(strPath,dwFileAttributes)){AfxMessageBox("File Attributes set success!\r\n");}CString ShowFileTime(LPFILETIME lpTime){//file time structFILETIME fileTimeLocal;SYSTEMTIME systemTime;CString strFileTime;FileTimeToLocalFileTime(lpTime,&fileTimeLocal);FileTimeToSystemTime(&fileTimeLocal,&systemTime);strFileTime.Format(_T("%4d年%2d月%2d日,%#02d:%#02d:%#02d"),systemTime.wYear,systemTime.wMonth,systemTime.wDay,systemTime.wHour,systemTime.wMinute,systemTime.wSecond);return strFileTime;}