How can I search for files that are either compressed or uncompressed in Windows Explorer?

I know that Windows explorer can colorize the NTFS compression state of a file, in both the regular and search views.

How can I specifically filter/search for files that are compressed or uncompressed on NTFS level?

Preferably a solution that works in Windows XP and higher (there are quite a few hardware devices for which no drivers are available for anything Vista and up).

Since Windows Search is too CPU intensive I'd like a solution without that as well.


Command-line interface

Windows XP doesn't provide a way to list compressed files out of the box, and even the advanced search methods aren't designed for such tasks. The command prompt comes to the rescue:

cd /d "C:\Some folder"
compact | findstr /c:" 1 C"

The cd command is simply used to navigate to the target directory. When the compact command is run without parameters it will list all files along with their compression details, if any. The output can be then filtered by redirecting it to findstr. For what is worth, this method should work even on Windows 2000.

Still, the output is quite verbose. To strip out the extra information some more work is required:

for /f "tokens=9,*" %A in ('"compact | findstr /c:" 1 C" "') do @dir /b "%A*%B" 2>nul

The command above will display compressed file names only. The dir command will help validating the file names to avoid false positives (e.g. those containing the string 1 C in their name).

Additional parameters you can use are:

  • /s Applies the command to all subfolders.
  • /a Displays hidden or system files.

Note that those parameters have to be used both for compact and dir commands, if needed.

To list uncompressed files, you can use the /v parameter of the findstr command to reverse the filter, and change the tokens value to 8 (that's because uncompressed files don't have the C marker, which affects the string tokenization).

Further reading

  • Command-Line Reference

Advanced Query Syntax

Windows Search queries are specified in Advanced Query Syntax (AQS) which supports not only simple text searches but provides advanced property-based query operations as well.

Source: Windows Search - Advanced Query Syntax

AQS was first introduced with Windows Desktop Search, which was later improved and integrated into Windows Vista as Windows Search. You need to install it separately in earlier operating systems.

The following query will list all files which are have the archive attribute set and are compressed. It works in Windows XP, Vista and 7. It should also work in Windows 8.x, although I didn't test.

System.FileAttributes:(2080)

In English locales you can also use:

attributes:(2080)

Here's a list of the most useful values:

FILE_ATTRIBUTE_READONLY = 1
FILE_ATTRIBUTE_HIDDEN = 2
FILE_ATTRIBUTE_SYSTEM = 4
FILE_ATTRIBUTE_ARCHIVE = 32
FILE_ATTRIBUTE_COMPRESSED = 2048
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192

In the example above I combined FILE_ATTRIBUTE_ARCHIVE and FILE_ATTRIBUTE_COMPRESSED: 32 + 2048 = 2080.

You can search any combinations by using the logical OR operator. For example, to search compressed files which are either read-only or not:

System.FileAttributes:(2080 OR 2081)

To invert the search results you can use the NOT operator:

System.FileAttributes:NOT(2080 OR 2081)

Further reading

  • Advanced tips for searching in Windows
  • Advanced Query Syntax
  • File Attribute Constants