Export (0) Print
Expand All


The virtual version of GetStatus retrieves the status of the open file associated with this CFile object.

BOOL GetStatus(
   CFileStatus& rStatus 
) const;
static BOOL PASCAL GetStatus(
   LPCTSTR lpszFileName,
   CFileStatus& 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.
  • LONG 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.
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 name.

Return Value

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


It does not insert a value into the m_szFullName structure member.

The static version gets the status of the named file and copies the filename to m_szFullName. This function obtains the file status from the directory entry without actually opening the file. It is useful for testing the existence and access rights of a file.

The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:

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


//example for CFile::GetStatus
CFileStatus status;
extern CFile cfile;
if( cfile.GetStatus( status ) )    // virtual member function
      #ifdef _DEBUG
         afxDump << "File size = " << status.m_size << "\n";
char* pFileName = "test.dat";
if( CFile::GetStatus( pFileName, status ) )   // static function
      #ifdef _DEBUG
         afxDump << "Full file name = " << status.m_szFullName << "\n";

See Also

CFile Overview | Class Members | Hierarchy Chart | CFile::SetStatus | CTime

© 2015 Microsoft