Compartir a través de


CFile::GetStatus

This method retrieves status information related to a given CFile object instance or a given file path.

BOOL GetStatus(
   CFileStatus& rStatus 
) const;
static BOOL PASCAL GetStatus(
   LPCTSTR lpszFileName,
   CFileStatus& rStatus 
);

Parameters

  • rStatus
    A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields:

    • CTime m_ctime   The date and time the file was created.

    • CTime m_mtime   The date and time the file was last modified.

    • CTime m_atime   The date and time the file was last accessed for reading.

    • ULONGLONG m_size   The logical size of the file in bytes, as reported by the DIR command.

    • BYTE m_attribute   The attribute byte of the file.

    • char m_szFullName[_MAX_PATH]   The absolute filename in the Windows character set.

  • lpszFileName
    A string in the Windows character set that is the path to the desired file. The path can be relative or absolute, or it can contain a network path name.

Return Value

TRUE if the status information for the specified file is successfully obtained; otherwise, FALSE.

Remarks

The non-static version of GetStatus retrieves status information of the open file associated with the given CFile object. The static version of GetStatus obtains the file status from a given file path without actually opening the file. This is useful for testing the existence and access rights of a file.

The m_attribute member of the CFileStatus structure refers to the file attribute set. The CFile class provides the Attribute enumeration type so file attributes can be specified symbolically:

enum Attribute {

normal = 0x00,

readOnly = 0x01,

hidden = 0x02,

system = 0x04,

volume = 0x08,

directory = 0x10,

archive = 0x20

};

Example

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);
}

Requirements

Header: afx.h

See Also

Concepts

CFile Class

CFile Members

Hierarchy Chart

CFile::SetStatus

CTime Class