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(LGetFileAttributesEx() pretty damn failed, error %u\n, GetLastError());



            wprintf(LGetFileAttributesEx() 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(LFile size is %u bytes\n, dwFileSize);


            FileTimeToSystemTime(&data.ftLastAccessTime, &times);

            SystemTimeToTzSpecificLocalTime(NULL, &times, &stLocal);

            wprintf(LLast 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(Ldata.dwFileAttributes \'sum\' value is %u\n, data.dwFileAttributes);


            // Let play around with some of the attributes

            if(data.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)

                  wprintf(LThe file is compressed!\n);


                  wprintf(LThe file is not compressed!\n);


            if(data.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)

                  wprintf(LThe file is an archive!\n);


                  wprintf(LThe file is not an archive!\n);


            if(data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)

                  wprintf(LThe file is hidden!\n);


                  wprintf(LThe file is not hidden!\n);


            if(data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)

                  wprintf(LThe file is read only!\n);


                  wprintf(LThe file is not read only!\n);


            if(data.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED)

                  wprintf(LThe file is an encrypted!\n);


                  wprintf(LThe 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 >