Windows Tip Sheet

Put Files on a Diet

Trim the fat off of your file servers with this nifty file compacting trick.

In my last column, I showed you how to use a couple of FOR expressions from the command line to clear out old, junk files. We can use this technique to put some of your files on a diet using file compaction.

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.

Tech Help—Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the editors at mailto:[email protected]; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

Here is a variation from what we used last time. As with all my examples, this is a single-line command:

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 compact them. I’m using /I to ignore any errors and /Q to only display 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.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.