How to use compact.exe to free up disk space on Windows
Microsoft introduced new options for the command line tool compact.exe in the Windows 10 operating system. It allows users to compress folders on the system using new algorithms to free up disk space.
Unlike many other compression solutions, compact promises to have little impact on performance when the files need to be loaded by the system. Files are compressed without changing the file extension or location. Decompression happens during runtime, and most modern systems should not break a sweat doing so. The tool is included in Windows 11 as well.
Compact.exe compresses files and folders on Windows without changing filenames or making other modifications to the files. Depending on the type of files, compression may save Gigabytes of disk space or very little. Files that are compressed already, e.g., JPG image files, will show little gains when compress is run on them. Uncompressed files on the other hand may show large gains. You can check out this GitHub page, which lists hundreds of games and programs, and the savings when using compress.exe on them.
A few applications and games may react badly to compression. If that is the case, uncompressing will resolve the issue.
Tip: if you prefer a graphical user interface, check out CompactGUI. Windows includes an option to compress the entire drive. Right-click on any drive in explorer and select Properties to open the option. You find "Compress this drive to save disk space" under General in the properties window.
Using compact.exe on Windows
You may run the program from any command prompt window. Open a new command prompt window, e.g., by using Windows-R to open the run box, typing cmd.exe and hitting the Enter-key on the keyboard.
Running compact on its own displays the compression status of all folders and files of the current directory.
The command line tool support several parameters, some of which may be confusing at first.
The core commands compact.exe /c and compact.exe /u mark the current or specified directories so that future changes to the folder, e.g., modified files or newly added files, are compressed or uncompressed.
It is necessary to supply the /s parameter to the command to perform the selected operation on all files in the specified directory and all of its subdirectories.
By default, the current directory is used, but a directory may be supplied to perform the operation on a different directory instead. To do that, add path information to the command.
The command compact.exe /c /s:c:\users\test\downloads\ runs the compression on the downloads directory.
You may specify the compression algorithm by supplying the /EXE parameter. The parameter /EXE:XPRESS8K uses that algorithm. The following algorithms are supported:
- XPRESS4K (fastest and default value)
- LZX (most compact)
The default algorithm is designed to make the performance impact as minimal as possible, even on older systems. Most devices should not have issues using the 8k or even 16k algorithm instead.
Other useful parameters of compact.exe:
- /f forces the compression or uncompression. Already compressed or uncompressed files are skipped. Should be used if the process was interrupted, e.g., by a crash.
- /i ignores errors and continues the operation without stopping.
- /? displays help information.
Large program and game folders, and folders with large uncompressed files, benefit the most from the compression. Gigabytes of disk space may be recovered with the help of the command. Most Windows users may use the CompactGUI program instead, as it is easier to use and handle.
Now You: have you used compact.exe in the past?
“game folders” + “compression”?? Good luck with that.
Cpu time will increase if you compress often used content, making nvme 3gb/s+ loads of data take forever. But unity games tend to compress to 50% or better, worth for games you play rarely. Defrag becomes a problem as windows’ in-place compression can drive fragmentation up to 100k times, a neat way to increase write amplification to kill ssds and spinning discs alike if left as is.
Clonespy with deduplication to hardlinks, is usually a less troublesome way to save space, as is dism renoval of unused windows features.
Microsoft devs still stuck in 1995.
Compression on a games folder like Steam can net a lot of space. However, during updates, it can be very time consuming and the write amplification will wear out an SSD fast.
The command line? And people bitch about Linux.
Grandma would never be able to accomplish much in the Windows command line.
Just another reason why Windows is not ready for the desktop.
My grandma could do it.
I whole hardily agree. The last thing most users want to do is tinker with ‘command line’.
Computers, ipones, ipads and the like are more like an appliance. People just want them to
work. They are ready to trade or dump them if they break.
Cars are the same way. People tend to just want to put gas and them an be on their way.
The last thing they want to do is open their hood, check their tires air pressure etc.
I’ve never understood why Microsoft doesn’t want to make a tool to convert files to sparse. Yes, I know, you can flag an existing file as sparse, but to convert it to a true sparse file you first need to make a sparse file and then copy the relevant info into it and then delete the original. And there isn’t any tool I know of that does that easily. (I so far haven’t found one that works anyway. And remember, this has to be a batch operation. And yes, this would change the file’s checksum if you have a game or program that checks that.)
Why use sparse files at all? Surely the gains must be minimal unless you’re dealing with databases? True, for individual files, but overall the space savings could add up to alot….theoretically….since I’ve never seen an entire Windows install made sparse. Which most of it could.
Sparse files are supported on all modern versions of Windows (At least Windows 7 and up, Server included.), are supported on both NTFS and ReFS (Several Linux file systems too, since Microsoft wants a Linux sub-system on future editions.), wouldn’t add more CPU cycles than needed (NTFS compression and other filesystem compression schemes have to re-compress the read file back to the disk if it’s changed at all. I think NTFS recompresses the file regardless of write status.), and finally sparse files don’t care about NTFS cluster size (Or block size for Linux filesystems.) so you would get both the read speed increase from larger clusters and the advantage of smaller sizes from sparse files. (NTFS compression won’t work on anything except the default 4k cluster size.)
Only one disadvantage and this applies to Windows and Linux. Without some behind the scenes trickery, a file copied to another volume loses it’s sparse status. To get around this, you need to do the same trick that let you convert a file to sparse in the first place. (As in, creating a new sparse file on the new volume and just copying the relevant data minus the zeros to it.) But, if you’re just reading from a remote volume in say, a media server setup, for example, it stays sparse and just reads relevant data.
Plus something else- install images would be smaller. Correct me if I’m wrong, but aren’t ALL install images for ALL editions of modern Windows in NTFS? Whether you install Windows 10, 11, or Server, you’re in an NTFS enviroment. A cut down one, yes, but still sparse compatible. Right? Again, not huge space savings, but they add up. Microsoft can even offer it as an advertsing thing that says the “new” Windows 11 install image went down to 3-4gb from it’s current 5gb+ size. Maybe?? Losing a gig or nearly a gig wouldn’t be too bad. And they wouldn’t be changing anything or creating new software.
I mean, am I missing something? It’s an old and well understood technology and it’s just sitting there. I’m sure people will point out details I’m missing, but it seems like a better answer.
“My grandma could do it.”
Careful. Grandmas now are the ones that worked in VMS, OS/400, CPF, etc.
Just a thought.
I hope you’re being paid well.
This is a horrible idea. Did you bother testing it? How about on a spinning disk?
This uses (I believe) the wof filter driver. the feature is for shitty endpoints with small storage footprints (compact flash based tablets, etc). I’d never recommend this on a prod system.
Much better off doing disk cleanup wizard (or dism /online functions)
I really love the size preview function of CompactGUI for games where it estimates the size of the ‘compacted’ game folder.