File Systems

Compact is the command-line version of the real-time NTFS compression functionality used in Windows Explorer. Compact displays and alters the compression of folders and files on NTFS volumes. It also displays the compression state of folders. The syntax of Compact is:

compact [/c|/u] [/s[: folder ]] [/a] [/i] [/f] [/q] [ filename [...]]

TableĀ 17.14 describes the switches available with Compact.

TableĀ 17.14 Compact Switches

Switch

Description

none

Displays the compression state of the current folder.

/c

Compresses the specified folder or file.

/u

Decompresses the specified folder or file.

/s [ :folder ]

Specifies that the requested action (compress or decompress) be applied to all subfolders of the specified folder, or to the current folder if none is specified.

/a

Displays files with the hidden or system attribute.

/i

Ignores errors.

/f

Forces a specified folder or file to compress or decompress.

/q

Reports only the most essential information.

filename

Specifies a file or folder. You can use multiple file names and wildcard characters.

/?

Displays user help.

The following are reasons to use this tool rather than the Windows Explorer equivalent:

  • You can use Compact in a batch file. Using the /i switch enables you to skip files that cannot be opened when you are running in batch mode, such as files already in use by another program.

  • If the system failed during compression or decompression when using Windows Explorer, the file or folder is marked as Compressed or Uncompressed, even if the operation did not complete. You can force the operation to complete by using Compact with the /f switch (with either the /c or /u switch).

note-icon

Note

Compact automatically compresses or decompresses all of the files and subfolders when you change the compression state of a folder. It does not ask whether you want to change the compression state of the files or subfolders in it.

For more information about real-time compression support in NTFS, see Volume, Folder, and File Compression earlier in this chapter.

When you attempt to compress a volume that is very low on free space, you might receive an error indicating that there was insufficient space to perform the action.

These errors indicate that the system needs additional free space to perform a compression. The system is not designed to manipulate the data in place on the disk. Additional space is needed to buffer the user data and to possibly hold additional file system metadata. The amount of additional free space required depends on the cluster size, file size, and available space.