The Windows File Management 8






Compressed File (Attributes) Program Example


The following program example demonstrates some of the compressed file functions.

Create a new empty Win32 console application project. Give a suitable project name and change the project location if needed.

Then, add the source file and give it a suitable name.

Next, add the following source code.


#include <windows.h>

#include <stdio.h>


int wmain(int argc, WCHAR *argv[])


      BOOL bRetVal;

      // Make sure the file is exist

      LPCTSTR lpFileName = L"\\\\?\\C:\\WINDOWS\\ie7\\iexplore.chm";

      // LPCTSTR lpFileName = L"\\\\?\\C:\\amad\\AddUserEncryptFile\\Debug\\testfilencrypt.doc";


      GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard;

      SYSTEMTIME times, stLocal;

      DWORD dwFileSize = 0;

      // File  less than 4GB does not need this

      LPDWORD lpFileSizeHigh = NULL;


      bRetVal = GetFileAttributesEx(lpFileName, fInfoLevelId, &data);


      if(bRetVal == 0)

            wprintf(L"GetFileAttributesEx() pretty damn failed, error %u\n", GetLastError());



            wprintf(L"GetFileAttributesEx() is working!\n");


            // dwFileSize is the low-order DWORD of the actual number

            // of bytes of disk storage used to store the specified file

            dwFileSize = GetCompressedFileSize(lpFileName, lpFileSizeHigh);


            wprintf(L"File size is %u bytes\n", dwFileSize);


            FileTimeToSystemTime(&data.ftLastAccessTime, &times);

            SystemTimeToTzSpecificLocalTime(NULL, &times, &stLocal);

            wprintf(L"Last accessed: %02d/%02d/%04d %02d:%02d:%02d\n", stLocal.wDay , stLocal.wMonth,

                  stLocal.wYear, stLocal.wHour, stLocal.wMinute, stLocal.wSecond);


            // The value is bitwise AND lol

            wprintf(L"data.dwFileAttributes \'sum\' value is %u\n", data.dwFileAttributes);


            // Let play around with some of the attributes

            if(data.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)

                  wprintf(L"The file is compressed!\n");


                  wprintf(L"The file is not compressed!\n");


            if(data.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)

                  wprintf(L"The file is an archive!\n");


                  wprintf(L"The file is not an archive!\n");


            if(data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)

                  wprintf(L"The file is hidden!\n");


                  wprintf(L"The file is not hidden!\n");


            if(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)

                  wprintf(L"The file is read only!\n");


                  wprintf(L"The file is not read only!\n");


            if(data.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED)

                  wprintf(L"The file is an encrypted!\n");


                  wprintf(L"The file is not encrypted!\n");



      // You may want to try other attributes:

      // data.ftCreationTime;

      // data.ftLastWriteTime;

      // data.nFileSizeHigh;

      // data.nFileSizeLow;


      // Close handle  


      return 0;



Build and run the project. The following screenshot is a sample output.


Compressed File (Attributes) Program Example: A sample console program output in action


From the file property's page, we can see that the size on disk. Click the Advanced button for other information.


The file size on disk


Well, the file is a compressed file (blue in colour). Both file size and compressed attribute should confirm our program output.


The compressed file attribute





< Windows Files 7 | Win32 Programming | Win32 File Index | Windows Files 9 >