How to create a compressed folder in Windows using Win32 API

by ixmx


void create_zipped_folder(string & folder_name)
{
   if(CreateDirectory(folder_name.c_str(),NULL))
   {
      HANDLE hFile = CreateFile(folder_name.c_str(),
                        GENERIC_READ | GENERIC_WRITE,
                        NULL,
                        NULL,
                        OPEN_EXISTING,
                        FILE_FLAG_BACKUP_SEMANTICS,
                        NULL);

      DWORD dummy;
      USHORT format = COMPRESSION_FORMAT_DEFAULT;
      if(!DeviceIoControl(hFile, FSCTL_SET_COMPRESSION, &format, sizeof(USHORT), NULL, 0, &dummy, NULL))
      {
         ErrorExit(TEXT("DeviceIoControl Failed"));
      }

      CloseHandle(hFile);
   }
}
About these ads