How to Use the makecab Command to Compress Files Natively in Windows 11

The Origins of makecab

When you need to compress a file in Windows 11, the easiest method is to simply right-click the file and select “Compress to ZIP file”. However, if you are writing an automated batch script to back up server logs, or if you are working in a minimalist Server Core environment without a graphical interface, you need a command-line compression tool.

While PowerShell has the Compress-Archive cmdlet, it can sometimes be slow and resource-intensive on older systems. Long before ZIP files became the universal standard, Microsoft used the Cabinet (.cab) file format to compress software installation files. The tool used to create these files is called makecab. It has been built into every version of Windows since the 1990s and remains an incredibly fast, lightweight, native command-line compression utility.

Step 1: Compressing a Single File

To compress a single file using makecab, you simply open the Command Prompt (or PowerShell) and type the command followed by the name of the file you want to compress.

For example, to compress a large database dump named inventory.sql:

makecab inventory.sql

By default, makecab will create a compressed file in the exact same directory and automatically append an underscore (_) to the end of the original file extension to indicate it is a cabinet file. In this case, the output file will be named inventory.sq_.

If you prefer the output file to have a standard .cab extension (which makes it easier for other Windows users to extract by double-clicking), you can explicitly define the destination name:

makecab inventory.sql inventory_backup.cab

Step 2: Understanding Directive Files (DDF)

The main limitation of a basic makecab command is that it can only compress one single file at a time. If you try to run makecab foldername\*, it will fail.

To compress multiple files into a single .cab archive, you must use a Diamond Directive File (.ddf). This is simply a plain text file that contains a list of instructions telling makecab exactly how to build the archive.

Open Notepad and create a file named backup.ddf. Enter the following text:

.OPTION EXPLICIT
.Set CabinetNameTemplate=ServerLogs.cab
.Set DiskDirectoryTemplate=C:\temp\backup_output
.Set CompressionType=LZX
.Set Cabinet=on
.Set Compress=on

C:\logs\error.log
C:\logs\access.log
C:\logs\security.log

Breaking down the DDF:

  • CabinetNameTemplate: The name of the final compressed archive.
  • DiskDirectoryTemplate: The folder where the final archive will be saved.
  • CompressionType: LZX provides the highest compression ratio available for CAB files (the alternatives are MSZIP or NONE).
  • The File List: The very bottom of the file is a simple list of the absolute paths to the files you want to include in the archive.

Step 3: Compressing Multiple Files

Once you have saved your backup.ddf file, return to the Command Prompt.

You execute the directive file by using the /f (file) flag:

makecab /f C:\temp\backup.ddf

The tool will instantly read the instructions, compress the three log files using LZX compression, and output the highly compressed ServerLogs.cab file into your designated folder.

How to Extract a CAB File

If you send a .cab file to another Windows 11 user, they can usually double-click it in File Explorer to view the contents, and drag the files out to extract them.

However, if you need to extract the files via the command line, you cannot use makecab. You must use its sister command, expand.

expand ServerLogs.cab -F:* C:\temp\extracted_logs\

This command extracts all files (-F:*) from the CAB archive into the specified destination folder.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.