How do I define search filters?
*********************************

In order to create a new filter, follow these steps:

Start by clicking "+". Then select what you want to search for in the first filter box.

.. tip::

    Are you searching for files with a specific name? Select "Name".
    Should a filter for file size be created? Select "Size".
    Are you looking for files of a specific type? Select "File Type" etc. (A variety of values to compare against are available. See also :ref:`available_filters`).

In the second field, select how the elements should be compared:

A search for file names, for instance, can look for characters that are contained in the name, or whether it starts or ends with it.

More complex comparisons can be performed with the option "matches pattern", or "matches regular expression".

Examples for this are simple wildcard patterns such as ``.exe``, or regular expression patterns such as ``.+\.exe$``.

The opposite of a filter is also possible. You can search for files that do not contain a certain string. This can be used to exclude certain files from your search results.

Lastly, define the value of the filter. This value will be compared against the file name, size, etc.

.. image:: /images/TreeSize-FileSearch_Excludefilters.png
   :width: 100%
   :align: center

Combining multiple filters with each other
=============================================

Multiple filters can be combined with each other as well. You can define multiple filters that will be applied one after the other, using the method that you have selected.

You can fully customize whether filters will be combined via ``Or`` conjunction, or via ``And`` conjunction. The former means that at least one of the filters has to apply, the latter means that all of them must match.

A filter definition is always located below either an ``And`` or an ``Or`` node of the tree structure. This node defines how the underlying filters should be combined.

Tips for Powerusers
~~~~~~~~~~~~~~~~~~~~~~

When combining multiple different filters, where part of them is to be combined via ``Or``, while others are to be combined via ``And``, it might seem a bit challenging to keep the overview, upon first use, since the arrangement in a tree structure does not match our usual reading direction.

However, thanks to this compact and clearly structured representation, elements can be nested as deeply as desired, making complex combinations possible that can cover almost any use case.

Since elements that belong together share the same higher-level node in the tree, it is often advisable to read the structure from the inside out, i.e. first look at the leaf elements of the tree, and then the respective higher-level elements.

The "Exclude system files" template shows an example of such a complex combination and is intended to provide an introduction to help you find your way around the definition of more complex filter definitions.

Using Wildcards
=================

If you select the option "matches pattern" for a filter type, you can create a more complex filter, where certain parts of the search term are replaced by a placeholder.

* Replaces none or arbitrarily many alphanumeric characters.

? Replaces exactly one alphanumeric character.

:ref:`regular-expressions` can also be used as patterns by selecting the comparison method "matches Regular Expression". The following table shows an example of possible patterns:

.. list-table::
   :widths: 20 20 30 30

   * - Name
     - matches pattern
     - ``.doc``
     - Searches for all files with the extension ".doc".
   * - Name
     - matches Regular Expression
     - ``[^\x00-\x7F]``
     - Find all files/folders with invalid ASCII characters.
   * - Full path
     - matches pattern
     - ``*\Windows\System32\*.exe``
     - Searches for all applications in the path "Windows\\System32".
   * - Name
     - matches Regular Expression
     - ``(?=.*a)(?=.*b)``
     - Find all files/folders containing at least one "a" character and one "b" character.
   * - Name
     - matches pattern
     - ``admin*``
     - Searches for all files with a file owner starting with "admin..." (e.g. "Administrator" or "Administrators").