Microsoft KB Archive/314958

= HOW TO: Use the COMPRESS, COMPACT, and EXPAND Commands to Compress and Expand Files and Folders in Windows 2000 =

PSS ID Number: 314958

Article Last Modified on 12/18/2003

-

The information in this article applies to:


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional
 * Microsoft Small Business Server 2000

-



This article was previously published under Q314958



IN THIS TASK

 * SUMMARY
 * ** How to Use the Compact Command to Compress Files and Folders
 * *** Examples
 * How to Use the Compress Command to Compress Files
 * *** Examples
 * How to Use the Expand Utility to Expand Files
 * *** Examples
 * REFERENCES



SUMMARY
This step-by-step article describes how to use the compact and the compress commands to compress files and folders in Microsoft Windows 2000.

back to the top

How to Use the Compact Command to Compress Files and Folders
Compact.exe is the command-line version of the file and folder compression feature in Windows 2000. Use Compact to compress, to decompress, or to display the compression state of files and folders on NTFS file system-formatted volumes.

Use the following syntax for the compact command:

compact /c /u /s: /a /q /i /f  ...

You can use the following parameters with the compact command:
 * no parameter: When you do not specify any parameters, the compression state of the current folder is displayed.
 * /c: This parameter compresses the specified file or folder.
 * /u: This parameter decompresses the specified file or folder.
 * /s: : This parameter specifies that the requested compress or decompress action is applied to all subfolders of the specified folder, or to the current folder if you do not specify one.
 * /a: This parameter displays files with the hidden or with system attribute.
 * /q: This parameter reports only the most essential information.
 * /i: This parameter ignores any errors that may occur.
 * /f: This parameter forces the compression or the decompression of a specified folder file or folder.

If the hard disk fails during a compression or decompression operation, the file or folder is marked as Compressed or Decompressed, even if the operation did not complete. In this situation, use the /f parameter to force the completion of the compress or the decompress operation.
 *  : This parameter specifies a pattern, a file, or a folder. You can use multiple file names, the asterisk (*) wildcard character, and the question mark (?) wildcard character with this parameter.

back to the top

Examples:
 To compress all files that are in the current folder and in the current subfolders, and to set the Compressed attribute on these folders, type the following command line from the command prompt, and then press ENTER:

compact /c /s

 To decompress all files that are in the current folder and in the subfolders, and to set the Decompressed attribute on these folders, type the following command line from the command prompt, and then press ENTER:

compact /u /s

 To compress all .bmp files that are in the \Graphics folder and its subfolders, but not change the compression state of these folders, type the following command line from the command prompt, and then press ENTER:

compact /c /s:\graphics *.bmp

 To decompress the C:\Temp folder, but not change the compression state of any files that are in that folder, type the following command line from the command prompt, and then press ENTER:

compact /u c:\temp

 To force the complete compression of the MyPic.bmp file, which was partially compressed during a hard disk failure, type the following command line from the command prompt, and then press ENTER:

compact /c /f mypic.bmp



back to the top

How to Use the Compress Utility to Compress Files
Compress.exe is a command-line utility that you can use to compress one or more files. This tool is included in the Microsoft Windows 2000 Resource Kit.

When you use Compress to compress files, you must use Expand.exe to expand the compressed file before you can open it.

NOTE: Do not use Compress to compress files or folders on NTFS-formatted volumes. To compress or decompress NTFS-formatted files or folders, use the Compact command-line utility or set the Compressed attribute of the file or the folder in Windows Explorer.

Use the following syntax for the compress command:

compress -r -d

You can use the following parameters for the compress command:
 * -r: This parameter renames the expanded file.
 * -d: This parameter updates a compressed file if it is no longer current.
 *  : This parameter specifies which source file to compress. You can use the asterisk (*) wildcard character, and the question mark (?) wildcard character with this parameter.
 *  : This parameter specifies the destination file, the folder, or the path. If   specifies multiple files and you do not use the -r parameter, the   parameter is a folder.

back to the top

Examples:
 To compress a file that is named MyPic.bmp in the C:\Temp folder to the E:\Pictures folder, type the following command line from the command prompt, and then press ENTER:

compress c:\temp\mypic.bmp e:\pictures

</li> To compress all .jpg files in the E:\Pictures folder, and then place them in the C:\Graphics folder, type the following command line from the command prompt, and then press ENTER:

compress e:\pictures\*.jpg c:\graphics

</li></ul>

back to the top

How to Use the Expand Utility to Expand Files
Expand.exe is a command-line utility that you use to expand files that were compressed by using the Compress utility. You can also use Expand to extract compressed files from a cabinet (.cab) file.

Use the following syntax for the expand command:

expand -r

expand -d .cab -f:

expand .cab -f:

You can use the following parameters for the expand command:
 * -r: This parameter renames the compressed file.
 * -d: This parameter displays a list of files that are in the source location.
 *  : This parameter specifies which source files to expand. You can use the asterisk (*) wildcard character and the question mark (?) wildcard character with this parameter.
 * -f: : This parameter specifies the files in a .cab file that you want to expand. Use the f:* parameter to expand all files in a .cab file. You can use the asterisk (*) wildcard character and the question mark (?) wildcard character with this parameter.
 *  : This parameter specifies the destination file, the folder, or the path. If   contains multiple files and you do not specify the -r parameter, the   parameter is a folder. You can use the asterisk (*) wildcard character, and the question mark (?) wildcard character with this parameter.

back to the top

Examples:
 To expand the compressed file, MyPic.bmp, in the E:\Pictures folder to the E:\MyDocs folder and to rename it to MyPhoto.bmp, type the following command line from the command prompt, and then press ENTER:

expand e:\pictures\mypic.bmp e:\mydocs\myphoto.bmp

</li> To expand a new Fontext.dll file from the I386 folder on your original Windows 2000 compact disc to the Winnt\System32 folder on your hard disk, type the following command line from the command prompt, where  is the drive in which Windows is installed, and where   is your CD-ROM or DVD-ROM drive, and then press ENTER:

expand d:\i386\fontext.dl_ c:\winnt\system32\fontext.dll

</li></ul>

back to the top

<div class="references_section">