WINDOWS TIP: FOR expressions to compact files.

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
compact them.

/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.

Source…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: