void CDemoDlg::OnGetFileInfo()
{
//创建文件对话框
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT, _T("所有文件(*.*)|*.*||"));
if (dlg.DoModal() == IDOK)
{
//获得文件路径
CString strPathName = dlg.GetPathName();
//获得文件信息
CFileStatus FileStatus;
if (CFile::GetStatus(strPathName, FileStatus))
{
CString strText = _T("");
CString strInfo = _T("");
strInfo.Format(_T("名称:%s\n"),
FileStatus.m_szFullName);
strText += strInfo;
strInfo.Format(_T("大小:%d字节\n"),
FileStatus.m_size);
strText += strInfo;
strInfo.Format(_T("创建时间:%d年%d月%d日,%02d:%02d:%02d\n"),
FileStatus.m_ctime.GetYear(),
FileStatus.m_ctime.GetMonth(),
FileStatus.m_ctime.GetDay(),
FileStatus.m_ctime.GetHour(),
FileStatus.m_ctime.GetMinute(),
FileStatus.m_ctime.GetSecond());
strText += strInfo;
strInfo.Format(_T("修改时间:%d年%d月%d日,%02d:%02d:%02d\n"),
FileStatus.m_ctime.GetYear(),
FileStatus.m_ctime.GetMonth(),
FileStatus.m_ctime.GetDay(),
FileStatus.m_ctime.GetHour(),
FileStatus.m_ctime.GetMinute(),
FileStatus.m_ctime.GetSecond());
strText += strInfo;
strInfo.Format(_T("访问时间:%d年%d月%d日,%02d:%02d:%02d\n"),
FileStatus.m_ctime.GetYear(),
FileStatus.m_ctime.GetMonth(),
FileStatus.m_ctime.GetDay(),
FileStatus.m_ctime.GetHour(),
FileStatus.m_ctime.GetMinute(),
FileStatus.m_ctime.GetSecond());
strText += strInfo;
CString strFileAttributes = _T("");
if (FileStatus.m_attribute & 0x00)
{
strFileAttributes += _T("无\n");
}
if (FileStatus.m_attribute & 0x01)
{
strFileAttributes += _T("只读\n");
}
if (FileStatus.m_attribute & 0x02)
{
strFileAttributes += _T("隐藏\n");
}
if (FileStatus.m_attribute & 0x04)
{
strFileAttributes += _T("系统\n");
}
if (FileStatus.m_attribute & 0x08)
{
strFileAttributes += _T("卷标\n");
}
if (FileStatus.m_attribute & 0x10)
{
strFileAttributes += _T("目录\n");
}
if (FileStatus.m_attribute & 0x20)
{
strFileAttributes += _T("存档\n");
}
strInfo.Format(_T("属性:%s"), strFileAttributes);
strText += strInfo;
AfxMessageBox(strText);
}
}
}
文件属性获取
最新推荐文章于 2024-09-02 22:15:22 发布