HOWTO compress a folder by command line

NTFS file system has the ability to compress files and folders to save disk space.  The only drawback is that they will be read and written slower than the normal ones.

Windows File Explorer displays them in blue instead of black, and it allows you to compress or expand by right-clicking them and selecting ‘Properties’ and then ‘Advanced’.

Suppose that you have to compress a folder but without using File Explorer, for instance, because you need different access rights.

You can do this by the following commands:

compact /c /s /i “<folder>”
compact /c /s /i “<folder>\*”

The first one will set ‘compression’ attribute to our <folder>, while the second one will compress all its contents.

To expand <folder> contents, use the following commands:

compact /u /s /i “<folder>”
compact /u /s /i “<folder>\*”