Windows Tip Sheet

Squish It

A nifty batch file trick to compress those ever-expanding log files.

If you have servers that are anything like I see at client sites, then this tip might buy you a little breathing room. Depending on the server, you may have a variety of services that are configured to generate log files. Over time these log files can get quite large and if not properly managed you can quickly end up with a log directory gigabytes in size. Certainly it would be to your advantage to periodically review logs and purge them as necessary, but that sort of work typically falls to the bottom of the to-do list, especially in shops with very limited manpower.

The tip is to compact the log folder. Since log files are text files, you can get great compression. You simply open Windows Explorer, right-click the log folder, typically C:\Windows\System32\Logfiles, choose Properties and compress the folder. But I have a better way because there are a few other directories and files you can compress on the system drive. The Debug folder also contains a number of log files. Within the Windows directory itself there are usually a number of bitmaps, text and log files that also compress nicely.

I use a batch file like this to compact the specified folders and files. The folders are marked as compressed so that new files will automatically be compressed.

compact /c /s:%windir%\system32\logfiles /i
compact /c /s:%windir%\debug /i
compact /c /f %windir%\*.log /i
compact /c /f %windir%\*.bmp /i

The /i parameter instructs the utility to ignore errors and keep working, It will skip any files it can’t compress that might be in use.

If you include this batch file in your server build process, then you’ll be ahead of the game. If you find you have a large number of files to process on an existing server, you might want to set up a scheduled task to run the batch file during off-peak hours.

Microsoft doesn’t recommend compressing files on the system drive, and I wouldn't compress files that are constantly in use. But once a log file is written and a new one started, the old file is rarely touched again -- it's just taking up space, so I don’t feel too guilty about compressing it. Plus, today’s servers have so much horsepower that a little bit of compression on active log files should be minimal.

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.