The filters in SyncBack allow for files and folders to be filtered based on their name. There are different filter types to choose from (see the Help file for details). This article gives examples using DOS Expressions, which is the default filter type.


First, there are three important rules to remember about filters:

  1. The selections in the tree override the filters. For example, you can filter out all .txt files but still select some .txt files in the tree.
  2. Filters apply to the entire filename, including the path, but the source and destination base are not part of the path. For example, if your source directory is C:\My Documents\ then that will not be in the filename used with the filter. This makes sense if you remember that the source and destination root directories are different, but their sub-directories are going to have the same names.
  3. Folder names end with a backslash, whereas files do not, e.g. \My Documents\ and \My Documents\filename.txt
  4. All file and folder names start with a backslash


Remember to include folders and files in the filter

If you set your Files/folders to copy filter to just *\*.txt then it will only include text files in the root folder and unselect all child folders. Why? Because you forgot to also include folders. You need to add *\ to Files/folders to copy as well to include all the folders (or change that as appropriate to include only folders with certain names, for example).

Another example is if you set your Files/folders to copy filter to just *\ then it will only include folders and no files. Why? Because all folders end with a backslash (\) but files do not. If you want to include all folders and files, the filter should be * (or *\*)


Filters are applied top-down

When SyncBack scans a folder it starts from the top (the root) and works its way down the child folders. For each file and folder, it first looks to see if it has been specifically selected, or not, in the file & folder selection tree. Selections override filters. If no selection decision has been made, it then uses the filters. It first checks to see if the file or folder matches any inclusion filter. If not, it is filtered out, i.e. skipped (ignored). If it's a folder that is being filtered out then all files and child folders of that folder are ignored. If it matches the filter then it checks to see if it matches an exclusion filter. If it does then it is filtered out.


For example, say you have the following folder structure:

\

\Parent\

\Parent\Child\

\Parent\Child\GrandChild\


The root folder (\) is always included and cannot be filtered out. After scanning the files in the root folder, it would then scan Parent, then Child, then GrandChild. Each folder must match a filter (or have been selected in the tree) otherwise everything in it is ignored. For example, if you had the following filter to copy all text files in the Child folder then it would fail:


\Child\*.txt


Why would it fail? Two reasons. First, because the Parent folder does not match that filter so the Child folder is never looked at. Second, the Child folder doesn't match that filter (it is \Parent\Child\). Folders end with a backslash. Therefore the filters must be changed to the following so the folders are included:


\Parent\

\Parent\Child\

\Parent\Child\*.txt


Absolute paths

Although you would usually use a relative path in a filter (e.g. \sub-folder\*.txt), with V11 you can use absolute paths. It will be used if the filters drive (or UNC path) matches either the source or destination drive (or UNC path). For example, if your source was C:\My Files\ and the destination was D:\My Backup\ then the filter C:\*cache*\ is valid as it is using the drive C: which the source also uses.


This can be useful when using variables in the filters that have absolute paths. For example, you may be copying everything on your C:\ drive (not recommended) but do not want to copy your Windows or Program Files folders. In that case you could use the following exclude filters:


%SystemRoot%\*

%ProgramFiles%\*

%ProgramFiles(x86)%\*


Example DOS Expressions

Notice that many of the examples below also include filters to include folders.

*\
*\*.txt
All text files (.txt) in all folders. The *\ filter ensures all folders are looked at.
*\
*\temp\*.txt
All text files in all folders called temp
\temp\
\temp\*.txt
All text files in the root folder called temp. For example, if your source directory is C:\My Documents\ then this filter is for all text files in C:\My Documents\temp\
*\test\All folders called test. Note that no files will be copied unless another filter is added to include files, e.g. *\*.txt
*\parent\
*\parent\child\
All folders called child whose parent directory is called parent. Notice the filter *\parent\ is required otherwise it will never look inside folders called parent. Note that no files will be copied unless another filter is added to include files, e.g. *\*.txt
\temp*\All root folders whose name starts with temp or is called temp. Note that no files will be copied unless another filter is added to include files, e.g. *\*.txt


Examples of wrong DOS Expressions

The examples below are examples of wrong filters. An explanation is given of why it is wrong.

*.txtThis will match any file, or folder, whose name ends with .txt. If you are trying to just include all text files then you should also remember to add *\ to the filters otherwise no child folders will be selected (see the notes below). If you just want text files in the root then the filter is valid if used on its own.
temp\*.txtThis filter will fail to match anything because all folder and filenames start with a backslash (\) character.