≡ Menu

How to compress file from command line

We can use compress.exe utility to compress a file from command line.
This tool is available for public download as part of windows server 2003 resource kit. It can be downloaded from the below location.

http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

After installing the above, you can find compress.exe tool in the directory “C:\Program Files\Windows Resource Kits\Tools”

The usage of this tool is explained below with examples.

To compress a file example.txt:
compress example.txt  compressedfile1.txt

Example:

C:\>”Program Files\Windows Resource Kits\Tools\compress.exe” sysinfo.txt sysinfo_compressed.txt

Microsoft (R) File Compression Utility  Version
Copyright (C) Microsoft Corp. 1990-1999.  All rights reserved.

Compressing sysinfo.txt to sysinfo_compressed.txt.
sysinfo.txt: 14211 bytes compressed to 3519 bytes, 76% savings.

Total savings: 1 files, 14211 bytes compressed to 3519 bytes, 74% savings.

C:\>


You can use “compress.exe filename -R” to automatically reanme the compressed files. This will be useful if you want to compress multiple files with single command. In this case you can’t specify the file names for all the compress ones so adding -R switch will automatically rename the compressed files.

If neither the output file name is specified nor -R switch is added then you will get an error like below.

C:\>”c:\Program Files\Windows Resource Kits\Tools\compress.exe” manual.pdf

How to compress all files in a directory
You can compress all files in a directory by using regular expression *.


Example:

C:\>”c:\Program Files\Windows Resource Kits\Tools\compress.exe”  *  -R

Microsoft (R) File Compression Utility  Version
Copyright (C) Microsoft Corp. 1990-1999.  All rights reserved.

Compressing August10.pdf to August10.pd_.
August10.pdf: 6571 bytes compressed to 6510 bytes, 1% savings.

Compressing July10.pdf to July10.pd_.
July10.pdf: 6573 bytes compressed to 6525 bytes, 1% savings.

Compressing June10.pdf to June10.pd_.
June10.pdf: 6574 bytes compressed to 6520 bytes, 1% savings.

Compressing May10.pdf to May10.pd_.
May10.pdf: 6540 bytes compressed to 6476 bytes, 1% savings.

Total savings: 4 files, 26258 bytes compressed to 26031 bytes, 0% savings.

C:\>


1 comment… add one
  • Maurice

    hola, y cómo se hace para descomprimir? Al dar doble click sobre el archivo no da opciones de descomprimir.
    hello, and how it is to decompress? By double clicking on the file does not uncompress options.

Leave a Comment