We all know that the best practice is to set the compact attribute at the folder level. But this isn’t always practical. Some files just don’t compact well, while others do. You may find it more advantageous to compact specific files that you know have great compression ratios like text, bitmaps and Word docs, while leaving other files untouched.
Here is a single-line command to compact such files:
FOR /f “tokens=*” %x in (‘dir C:\*.txt,*.bmp,*.vbs,*.doc /s /b’)do @compact /C /I /Q “%x”
This command will find all .TXT, .BMP, .VBS and .DOC files on C:\ and
/I ignores any errors
/Q displays only minimal information.
If you don’t want to see anything, simply redirect the entire expression to NUL.
FOR /f “tokens=*” %x in (‘dir C:\*.txt,*.bmp,*.vbs,*.doc /s /b’)do @compact /C /I /Q “%x” > NUL
Should you find yourself in need of reversing your decision, simply use /U instead of /C with the Compact command.
If you need to target some specific areas of your file servers to trim a little fat, this is a quick and easy method.