In the left pane, browse to the parent folder of the file or folder you want to compress. Click on the parent folder. This displays the list of subfolders and files in the right pane.
In the right pane, right-click on the target file or folder and select Properties.
Click the Advanced button.
Check the box beside Compress contents to save disk space.
Click OK and Apply.
> compact /c /s
This command also causes all future files added anywhere under the current directory to be compressed.
To decompress all the files in the current directory and cause
all future files to not be compressed, use the
/u option with
> compact /u /s
The following command compresses all of the files with the .doc extension (i.e., Word documents) in the c:\docs directory:
> compact /c /s:c:\docs *.doc
The compress.exe utility works a little bit differently from compact. It doesn't compress files transparently within the filesystem using NTFS compression. Instead it creates a compressed copy of a file. Here is an example:
> compress largetextfile.txt compressedfile.txt
The source file (largetextfile.txt) remains unchanged and the target file (compressedfile.txt) is a compressed version of that file. To compress all of the files in a directory, use this command:
> compress -R *.*
This creates compressed versions of each file and names them by replacing the last character of the source file with an underscore. For example, the compressed version of test.txt would be named test.tx_.
' This code compresses a folder and its contents using NTFS compression ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strFile = "
<FilePath>" ' e.g., d:\scripts\test.vbs ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFile = objWMI.Get("Cim_Datafile='" & strFile & "'") WScript.Echo objFile.Name intRC = objFile.Compress ' To uncompress change this to objFile.Uncompress if intRC <> 0 then WScript.Echo "There was an error compressing the file: " & intRC else WScript.Echo "File compression successful" end if ' This code compresses a folder and its contents using NTFS compression ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strFolder = "
<FolderPath>" ' e.g. d:\scripts ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFolder = objWMI.Get("Win32_Directory='" & strFolder & "'") intRC = objFolder.Compress ' To uncompress change this to objFolder.Uncompress if intRC <> 0 then WScript.Echo "There was an error compressing the folder: " & intRC else WScript.Echo "Folder compression successful" end if
NTFS compression is a great feature because once you compress a file, NTFS handles decompressing it automatically for you when you attempt to view it or copy/move it to another folder. However, you shouldn't start using compression everywhere. Decompressing and compressing files is CPU intensive. Be very careful when enabling compression on frequently accessed or modified files because it can have an adverse impact on performance.
MS KB 171892 (Err Msg: The File System Does Not Support Compression), MS KB 198038 (INFO: Useful Tools for Package and Deployment Issues), MS KB 251186 (Best Practices for NTFS Compression in Windows), MS KB 307987 (HOW TO: Use File Compression in Windows XP), MS KB 314958 (How To Use the COMPRESS, COMPACT, and EXPAND Commands to Compress and Expand Files and Folders in Windows 2000), and MS KB 323425 (HOW TO: Use the COMPACT Command to Compress and Uncompress Files and Folders in Windows Server 2003)