How to use compact.exe, the default Windows compression, in a batch file

23,159

compact doesn't do what you think it does, I think:

Displays or alters the compression of files on NTFS partitions.

COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]

It does the same as going to the folder properties and chosing "Compress contents to save disk space" - it does not create a ZIP (or similar) archive.

COMPACT /C /S:"C:\Somefolder"

It will use NTFS compression to shrink the folder on disk - not create a ZIP file, 7-Zip file or whatever.

Share:
23,159
sam
Author by

sam

Updated on May 06, 2020

Comments

  • sam
    sam almost 4 years

    I want to use the default Windows compression utililty for compressing a directory in a batch file. Currently I am using the following command, but it's not working.

    COMPACT /C /S source destination
    

    How do I use this from a batch file?

    Currently, I am doing the same using 7-Zip, but I need to do the same with compact.exe.

    START "Compressing Backup. DO NOT CLOSE" /belownormal /wait "%exe&Zip%" a -tzip -r -mx5 "%BackupFileDestination%" "%dirTempBackup%\"