It’s been said that you can never be too rich or have too much free hard disk space. Even with hard drive prices on a steady decline, it’s still important to squeeze all the space that you can out of your hard drives because today’s programs consume more space than ever before. One way to help increase free hard disk space is to use Windows NT’s compression feature. In this article, I’ll explain the Windows NT compression feature. Then, I’ll demonstrate how to use it in a batch file.
As you may know, the Windows NT disk compression feature allows you to compress entire partitions and folders or single files. Although it’s slower to use a compressed file than a non-compressed file, you can still use the file as if it weren’t compressed at all. Under normal circumstances, you can compress a resource through its properties sheet. The only stipulation is that the resource must reside on an NTFS partition.
To compress a partition, right-click on an NTFS partition in My Computer and select the Properties command from the context menu. You’ll see a Compress check box on the General tab. Selecting this check box will compress the entire partition. Likewise, you can compress a directory or a file by right clicking on it and choosing the Properties command from the context menu. When you see the resource’s General tab, select the Compressed check box to compress the resource.
Compression through batch files
Now that you know the basics of compression, you might find it handy to know that you also can compress resources through batch files. It’s especially helpful if you have a program that generates a lot of large files. You can schedule the batch file to run at certain intervals to compress the newly created files.
To compress resources through a batch file, use the COMPACT command. Several switches work with the COMPACT command to give you total control over the compression process. The syntax is as follows:
COMPACT [/C | /U] [/S[:DIR]] [/A] [/I] [/F] [/Q] [FILENAME]
- · /C—Compresses the specified files (The directory containing the files will be marked so that files added later will be compressed automatically.)
- · /U—Decompresses the specified files (This switch flags the directory so that files added later won’t be compressed.)
- · /S—Performs the specified operation on the specified directory and on all subdirectories beneath it
- · /A—Displays files with Hidden or System attributes, which are hidden by default
- · /I—Ignores errors and continues with compression when errors occur
- · /F—Compresses all files, even the ones that are already compressed (Already compressed files are skipped by default.)
- · /Q—Reports only the most essential information
- · Filename—Specifies a file, directory, or wildcard
You might notice a couple of side effects when working with compressed files in batch files. When you replace a file, it usually retains its compression state—regardless of the state of the folder and the new file. For example, if you copy a compressed file to a compressed folder but it overwrites an uncompressed file, chances are that the file still will be uncompressed. Naturally, this situation is only true when you’re working in NTFS. If you replace a file on a FAT partition with a compressed copy, the file will be uncompressed because FAT is incapable of supporting compression.
Brien M. Posey is an MCSE and works as a freelance technical writer and as a network engineer for the Department of Defense. If you’d like to contact Brien, send him an e-mail. (Because of the large volume of e-mail he receives, it's impossible for him to respond to every message. However, he does read them all.)The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.