CFile::GetStatus

函数原型:

BOOL GetStatus( 
   CFileStatus& rStatus  
) const; 

static BOOL PASCAL GetStatus( 
   LPCTSTR lpszFileName, 
   CFileStatus& rStatus, 
   CAtlTransactionManager* pTM = NULL 
);

参数

  • rStatus
    要获取状态信息的 CFileStatus 结构的引用。 CFileStatus 结构具有下列字段:

    • CTime m_ctime 文件创建日期和时间。

    • CTime m_mtime 文件的上次更新的日期和时间。

    • CTime m_atime 文件用于读取最后访问的日期和时间。

    • ULONGLONG m_size 文件的逻辑大小(以字节为单位),如报告DIR命令。

    • BYTE m_attribute 文件的属性字节。

    • char m_szFullName[_MAX_PATH] 在Windows字符集的绝对文件名。

  • lpszFileName
    在路径所需文件的Windows字符集的字符串。 路径可以是相对路径或绝对的,也可以包含网络路径名。

  • pTM
    为CAtlTransactionManager对象的指针

返回值

如果指定的文件的状态信息成功获取,返回TRUE;  否则,FALSE

说明

GetStatus 的非静态版本检索打开文件的状态信息与特定 CFile 对象。 GetStatus 的静态版本获取从特定文件路径的文件状态,而不会实际打开文件。 这将用于测试文件是否存在以及访问权限很有用。

CFileStatus 结构的 m_attribute 成员引用设置的文件属性。 CFile 选件类提供 Attribute 枚举类型,因此文件属性可以指定标记:

enum Attribute {

normal = 0x00,    readOnly = 0x01,     hidden = 0x02,     system = 0x04,     volume = 0x08,    directory = 0x10,    archive = 0x20

};

实例:

CFile cfile;
cfile.Open(_T("SetLength_File.dat"), CFile::modeCreate |
   CFile::modeReadWrite);
ULONGLONG dwNewLength = 10000;
cfile.SetLength(dwNewLength);
CFileStatus status;
if(cfile.GetStatus(status))    // virtual member function
{
   TRACE(_T("File size = %u\n"), status.m_size);
}
TCHAR* pszFileName = _T("SetLength_File.dat");
if(CFile::GetStatus(pszFileName, status))   // static function
{
   TRACE(_T("Full file name = %s\n"), status.m_szFullName);
}
发布了114 篇原创文章 · 获赞 120 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/alzzw/article/details/103710488