This segment of my review of the tools in the Microsoft Windows Server 2003 Resource Kit dives into the Compress.exe...
and Expand.exe utilities.
If you need to make a compressed copy of a file via a script or command line, then these utilities may help.
- The compress utility is a command-line tool that allows you to create compressed copies of files.
- The expand utility is a command-line tool that allows you to expand compressed files created by the compress utility.
The copy portion is the key to this compress utility. Most simple compression tools will allow you to compress the original file. Compress actually leaves the original target uncompressed, and instead makes a copy of that original and compresses it. It's important to note that this utility does not compress many files into a single file, such as a CAB file. If you choose to compress all the files in a directory (using a wildcard), it creates a single compressed file for each file in the source directory.
After compressing these files, you then use the Expand.exe utility to uncompress the data. You can also use Expand.exe to extract files from a cabinet (.cab).
- Windows 2000, Windows XP Professional, or Windows Server 2003 operating systems
- NTFS formatted volume
- Proper permissions on directory and files you wish to target
- Install the Resource Kit
General use: Compress Source Destination
C:\folder1> Compress text.txt c:\folder2 –r
The above example will copy a file in the folder1 directory named text.txt, and create a compressed version of that file in the folder2 directory. The compressed file will be named: text.tx_
- /r -- Renames expanded files. Compressed files are renamed with the last character in the file name extension set to an underscore ("_") character. The underscore identifies the file as a compressed file.
- /d -- Specifies that only out of date files within Destination are updated.
- /zx -- Specifies Lempel-Ziv (LZX) compression. The LZX compression can reduce the package size by up to 18% and increase the self-extracting speed by approximately 50%.
- /z -- Specifies MS-ZIP compression. This compression is also known as the .cab file format. It is based on the Lempel-Ziv data-compression algorithm.
- /zq[n] -- Specifies quantum compression. Valid values for n are in the range 1 to 7 (1 yields the fastest speed while 7 gives best compression). The default value for n is 4.
- Source -- Specifies the source file. The * and ? wildcard characters can be used.
- Destination -- Specifies the destination file or path, and the destination can be a directory. If Source specifies multiple files and /r is not specified, then Destination must be a directory. If the destination listed on the command line does not include a new file name for the compressed file, the file's original name is used (a new name is required to save the compressed file in the same folder as the original).
Expand Source Destination
C:\folder2> Expand text.tx_ c:\folder1\text.txt
The above example will expand a file in the folder2 directory named text.tx_ and create an uncompressed version of that file in the folder1 directory. The compressed file will be named: text.txt
- -r -- Renames expanded files.
- Source -- Specifies the files to expand. Source can consist of a drive letter and colon, a directory name, a file name or a combination of these. You can use wildcards (that is, * or ?).
- Destination -- Specifies where files are to be expanded. If Source consists of multiple files and you do not specify -r, Destination must be a directory. Destination can consist of a drive letter and colon, a directory name, a file name or a combination of these.
- -d -- Displays a list of files in the source location. Does not expand or extract the files.
- -f:Files -- Specifies the files in a cabinet (.cab) file that you want to expand. You can use wildcards (that is, * or ?).
Microsoft's help file oddly states, "Do not use Compress.exe (compress) to compress files or folders on the NTFS file system formatted files or folders. To compress or decompress NTFS-formatted files or folders, use the Compact command-line tool or set the Compressed attribute of the file or folder in Windows Explorer."
However, I don't quite understand this warning. True, the compress utility is old, but it seems to work just fine on an NTFS formatted volume, where the files and folders reside. I do know that you cannot use the built-in NTFS file properties dialog box to uncompress a file that has been compressed using this utility. Perhaps Microsoft wants you to make sure to use the compact tool instead so you can use the NTFS file properties windows to uncompress the file.
Windows XP appears to have a bug in that it cannot pass the source path. In other words, if you want to compress a file in the c:\folder1 directory to another directory called folder2, you cannot run the following command: compress c:\folder1\test.txt c:\folder2. If you do, you will receive an ERROR: Unable to open C:\folder1\test.txt message. The only way around this is to navigate to the directory that contains the source file, and then run the compress command. So, using the example above: c:\folder1> compress test.txt c:\folder2.
The Microsoft Windows Server 2003 Resource Kit tools are a set of tools to help administrators streamline management tasks, such as troubleshooting operating system issues, managing Active Directory®, configuring networking and security features, and automating application deployment.
About the author: Tim Fenner (MCSE, MCSA: Messaging, Network+ and A+) is a senior systems administrator who oversees a Microsoft Windows, Exchange and Office environment. He is also an independent consultant who specializes in the design, implementation and management of Windows networks.