CFileFind::GetLength

Call this member function to get the length of the found file, in bytes.

ULONGLONG GetLength( ) const;

Return Value

The length of the found file, in bytes.

Remarks

You must call FindNextFile at least once before calling GetLength.

GetLength uses the Win32 structure WIN32_FIND_DATA to get and return the value of the file size, in bytes.

Note

As of MFC 7.0, GetLength supports 64-bit integer types. Previously existing code built with this newer version of the library may result in truncation warnings.

Example

// This code fragment prints out a very verbose directory
// listing for all the files in the root directory on the
// C: drive. After the file's name, each attribute of the
// file is printed, as are the creation, last access, and 
// last write times.

CFileFind finder;

BOOL bWorking = finder.FindFile(_T("C:\\*.*"));

while (bWorking)
{
   bWorking = finder.FindNextFile();

   _tprintf_s(_T("%s\n\t"), (LPCTSTR)finder.GetFileName());
   _tprintf_s(_T("%c"), finder.IsArchived()   ? 'A' : 'a');
   _tprintf_s(_T("%c"), finder.IsCompressed() ? 'C' : 'c');
   _tprintf_s(_T("%c"), finder.IsHidden()     ? 'H' : 'h');
   _tprintf_s(_T("%c"), finder.IsNormal()     ? 'N' : 'n');
   _tprintf_s(_T("%c"), finder.IsReadOnly()   ? 'R' : 'r');
   _tprintf_s(_T("%c"), finder.IsSystem()     ? 'S' : 's');
   _tprintf_s(_T("%c"), finder.IsTemporary()  ? 'T' : 't');

   _tprintf_s(_T("\t%I64u byte(s)\n"), finder.GetLength());

   CTime tempTime;
   CString str;

   _tprintf_s(_T("\tCreated    : "));
   if (finder.GetCreationTime(tempTime))
   {
      str = tempTime.Format(_T("%c"));
      _tprintf_s(_T("%s\n"), (LPCTSTR) str);
   }
   else
   {
      _tprintf_s(_T("(unavailable)\n"));
   }

   _tprintf_s(_T("\tLast Access: "));
   if (finder.GetLastAccessTime(tempTime))
   {
      str = tempTime.Format(_T("%c"));
      _tprintf_s(_T("%s\n"), (LPCTSTR) str);
   }
   else
   {
      _tprintf_s(_T("(unavailable)\n"));
   }

   _tprintf_s(_T("\tLast Write : "));
   if (finder.GetLastWriteTime(tempTime))
   {
      str = tempTime.Format(_T("%c"));
      _tprintf_s(_T("%s\n"), (LPCTSTR) str);
   }
   else
   {
      _tprintf_s(_T("(unavailable)\n"));
   }

   _tprintf_s(_T("\n"));
} 

Requirements

Header: afx.h

See Also

Reference

CFileFind Class

Hierarchy Chart

Other Resources

CFileFind Members