Reference: Watchlist paths, inclusions, and exclusions

When you add paths to a watchlist, you can use wildcards and define path inclusions and exclusions to refine the list of files and directories to watch.

Paths

When you define a path, you can use wildcards within a directory or file name, but you cannot use them to specify multiple directory levels. This usage is different from wildcard usage in path inclusions or exclusions.

Examples

Example 1

You can add a path with a ? wildcard for any character in the path. On Windows, you can use this wildcard to specify that a specific folder should be watched, regardless of which drive it is on. If you add the path ?:\Program Files, the following directories are watched:

C:\Program Files
D:\Program Files
...

Example 2

When used in a path, the * wildcard can be used within a folder or file name, but cannot be used to specify multiple directory levels. For example, if you define the path /a/b*/c, the following files and directories are watched:

/a/b/c
/a/b/c/myfile.txt
/a/bin/c
/a/bin/c/myfile.txt
/a/b/c/d/myfile.txt

With only this path specified, the following files and directories are not watched:

/a/b
/a/b/c.txt
/a/b/d/c

Path inclusions

If you define path inclusions, only files and directories in the path that match the inclusion are watched for the configured change types (create, write, delete, rename, or permission). If you do not define any path inclusions, all files and directories in the path are watched for the configured change types.

Examples

Example 1

If you add the path /mypath and you add a path inclusion, test, the following directory is watched:

/mypath/test

With only this path and inclusion combination specified, these files and directories are not watched:

/mypath/test.txt
/mypath/test1
/mypath/test/myfile.txt
/mypath/mydir/test
/myotherpath/test

This example does not use wildcards in the inclusion, so only the single included directory is watched, non-recursively.

Example 2

If you add the path /mypath and you add a path inclusion, test*, the following directories and files are watched:

/mypath/test
/mypath/test.txt
/mypath/test1
/mypath/test/myfile.txt
/mypath/test/mydir/myfile.txt

With only this path and inclusion combination specified, this file is not watched:

/mypath/myfile.txt

This example uses a wildcard (*) at the end of the inclusion. The watchlist includes any combination of directory separators and valid path characters at the end of /mypath/test.

Example 3

If you add the path /mypath and you add a path inclusion, *test, the following directories and files are watched:

/mypath/test
/mypath/mydir1/mydir2/test
/mypath/Xtest
/mypath/mydir1/mydir2/Xtest
/mypath/myfile.test

This example uses a wildcard (*) at the beginning of the inclusion. The watchlist includes any combination of directory separators and valid path characters after /mypath that end with test.

Example 4

If you add the path /mypath and you add a path inclusion, test?, the following directories and files are watched:

/mypath/test1

With only this path and inclusion combination specified, these files and directories are not watched:

/mypath/test
/mypath/test.txt

This example uses a one-character wildcard (?) at the end of the inclusion. The watchlist includes any combination of directories and paths after /mypath that end with test plus one additional character.

Example 5

If you add the path /mypath and you add a path inclusion, */*.log, the following files are watched:

/mypath/mydir/mylog.log
/mypath/mydir/mysubdir/mylog.log

With only this path and inclusion combination specified, this file is not watched:

/mypath/mylog.log

This example defines an inclusion in which the matching file or directory must be in a directory that is at least one directory level below the path.

Path exclusions

If you define path exclusions, files and directories in the path that match the exclusion are not watched.

Examples

Example 1

If you add the path /mypath and you add a path exclusion, test, the following directory is not watched:

/mypath/test

With only this path and exclusion specified, these files and directories are watched because they are not excluded:

/mypath/test.txt
/mypath/test1
/mypath/test1/myfile.txt
/mypath/mydir/test

This example does not use wildcards, so only a single directory is excluded, non-recursively.

Example 2

If you add the path /mypath and you add a path exclusion, *, only the exact path is watched. The following directories are not watched:

/mypath/test
/mypath/mydir

With only this path and exclusion specified, these files and directories are watched because they are not excluded:

/mypath/test.txt
/mypath/test1
/mypath/test1/myfile.txt
/mypath/mydir/test

This example does not use wildcards, so only a single directory is excluded, non-recursively.

Path inclusions used with path exclusions

If you define both inclusions and exclusions for a path, all files and directories in the path are watched if they fall within one of the inclusion definitions for the path unless they also fall within one of its exclusion definitions.

Examples

Example 1

If you add the path /mypath and you add a path inclusion, mydir/*, and a path exclusion, *.log, the following files and directories are watched:

/mypath/mydir/myfile.txt
/mypath/mydir/mysubdir/myscript.sh

With only these inclusions and exclusions specified, the following file is not watched:

/mypath/mydir/myprogram.log

Example 2

You can use this pairing to define a path inclusion, but limit its depth. This configuration is useful for directories that have many nested directories and files, such as the C:\Windows\System32 folder.

If you add the path C:\Windows and you add a path inclusion, System32\*, and a path exclusion, System32\*\*, the following directory is watched:

C:\Windows\System32\wwapi.dll

With only these inclusions and exclusions specified, these directories are not watched:

C:\Windows\System32\WinMetadata\Windows.Data.winmd

This inclusion with a wildcard is paired with an exclusion ending in *\* to end the recursion at a specified depth. If you want to watch files in directories with depth n, add n+1 wildcards (*) separated by slashes (\ or /, depending on the target endpoint operating system).