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:
- 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.
- 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.
- Folder names end with a backslash, whereas files do not, e.g. \My Documents\ and \My Documents\filename.txt
- 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:
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:
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:
Example DOS Expressions
Notice that many of the examples below also include filters to include folders.
|All text files (.txt) in all folders. The *\ filter ensures all folders are looked at.|
|All text files in all folders called temp|
|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|
|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.
|*.txt||This 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\*.txt||This filter will fail to match anything because all folder and filenames start with a backslash (\) character.|