Tip

Exploring the Windows Server 2003 Resource Kit: Compress.exe and Expand.exe

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

    Requires Free Membership to View

to make a compressed copy of a file via a script or command line, then these utilities may help.

Per Microsoft:

  • 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).

Requirements:

  • Windows 2000, Windows XP Professional, or Windows Server 2003 operating systems
  • NTFS formatted volume
  • Proper permissions on directory and files you wish to target

Installation:

  • Install the Resource Kit

General use:
Compress Source Destination

Example:

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_

Parameters:

  • /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

Example:

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

Parameters:

  • -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 ?).

Issues:

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."

More on Windows Server 2003 Resource Kit:
How to use Windows Server 2003 Resource Kit's Clusterrecovery.exe

Demystifying the Acctinfo.dll tool in the Windows Server 2003 Resource Kit.

A guide to the Microsoft Windows Server 2003 Resource Kit Tools.
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.

This was first published in October 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.