﻿# Excluding files and directories from analysis

When checking your projects that use many third\-party libraries, you may need to focus on certain potential problems in your code\. For such purposes, PVS\-Studio tools provide a mechanism that excludes files from analysis\. The mechanism allows you not only to decrease the number of unnecessary warnings, but also to significantly speed up the analysis of your project\.

## Excluding files via IDE settings

### Visual Studio and C and C\+\+ Compiler Monitoring UI

In Visual Studio, open the settings of the plugin_ Extensions \-\> PVS\-Studio \-\> Options \-\> Don't Check Files_\.

If use the C and C\+\+ Compiler Monitoring UI utility, open_ Tools \-\> Option\.\.\. \-\> Don't Check Files_\.

In the window that appears, you can specify the files and directories to be excluded from the analysis\. You can also use wildcard masks\.

![Exclude_paths/image1.png](https://import.viva64.com/docx/blog/Exclude_paths/image1.png)

Note that not all masks in the Visual Studio plugin can be applied to filter an existing report\. If the mask is not applicable for filtering, you will receive a message stating that you need to restart analysis to apply the mask\. Masks with the '\*' character at the beginning and/or at the end are immediately applied to filter warnings in the plugin table\.

You can read more about excluding files via the plugin settings for Visual Studio [here](https://pvs-studio.com/en/docs/manual/0014/)\.

You can also exclude files from analysis via the context menu in the analyzer's report\. To do this, right click on the warning and select 'Don't check files and hide all messages from\.\.\.'\. In the drop\-down menu, you can select the nesting level of directories from which files should be excluded\.

![Exclude_paths/image3.png](https://import.viva64.com/docx/blog/Exclude_paths/image3.png)

**Note** that information about excluded directories and files is written to the global _Settings\.xml_ file\. That information can be used by other PVS\-Studio tools if the path for the settings file is not passed to them\.

### Plugins for CLion and Rider

To exclude files or directories from analysis, open the PVS\-Studio plugin settings \(_Tools \-\> PVS\-Studio \-\> Settings_\) and select the _Excludes_ section\.

![Exclude_paths/image4.png](https://import.viva64.com/docx/blog/Exclude_paths/image4.png)

In this section, you can manage the paths and masks of file names that will be excluded from the analysis\.

You can also exclude a file or a directory from the analysis directly through the context menu of the PVS\-Studio report\. To do this, right\-click on the message and select 'Exclude From Analysis'\. In the drop\-down menu, you can select the nesting level of directories from which files should be excluded\.

![Exclude_paths/image5.png](https://import.viva64.com/docx/blog/Exclude_paths/image5.png)

**Note** that information about excluded directories and files is written to the global _Settings\.xml_ file\. That information can be used by other PVS\-Studio tools if the path for the alternative settings file is not passed to them\.

## Excluding files via the Settings\.xml file

Console tools can use either the global _Settings\.xml_ file or a specific one passed as a command line argument\. A specific file can be useful if you have specific analysis settings for a project which should not affect the analysis results of other projects\. For example, a list of excluded directories\. 

To create an alternative settings file, copy the Settings\.xml file from the '%APPDATA%/PVS\-Studio/' \(Windows\) or '\~/\.config/PVS\-Studio' \(Linux\) directory to any place \(for example, to the directory of the project being checked\)\. Then add the excluded files and directories to the _ApplicationSettings/PathMasks_ node \(if it is a directory\) or to _ApplicationSettings/FileMasks_ \(if it is a file\)\.

For example:

```cpp
<ApplicationSettings ...>
  ...
  <PathMasks>
  ...
     <string>\EU*\Engine\Source</string>
  </PathMasks>
  ...
</ApplicationSettings>
```

Now, use the _\-\-settings \(\-s\)_ parameter to pass your custom settings file to _PVS\-Studio\_Cmd\.exe_ or pvs\-studio\-dotnet \(Linux and macOS\):

```cpp
PVS-Studio_Cmd.exe -t ProjName.sln -s /path/to/NonDefaultSettings.xml
```

To pass the parameter to _CLMonitor\.exe_ use the _\-\-settings \(\-t\)_ flag in any launch mode:

```cpp
CLMonitor.exe monitor -t /path/to/NonDefaultSettings.xml
```

## Excluding files via the diagnostic configuration file \(\.pvsconfig\)

You can create a file — _\.pvsconfig_ \(analyzer diagnostics configuration file\)\. In this file, you can use special comments to describe the files and directories to be excluded from analysis\. Read more about the \.pvsconfig file [here](https://pvs-studio.com/en/docs/manual/6630/)\.

To exclude a file or directory from analysis, all you need to do is specify its path or path mask — use the special _//V\_EXCLUDE\_PATH_ comment\.

For example:

```cpp
//V_EXCLUDE_PATH C:\TheBestProject\ThirdParty
//V_EXCLUDE_PATH *\UE*\Engine\Source\*
//V_EXCLUDE_PATH *.autogen.cs
```

Starting from PVS\-Studio 7\.34, you can use the _//V\_ANALYSIS\_PATHS_ comment with the _skip\-analysis_ mode\.

For example:

```cpp
//V_ANALYSIS_PATHS skip-analysis=C:\TheBestProject\ThirdParty
//V_ANALYSIS_PATHS skip-analysis=*\UE*\Engine\Source\*
//V_ANALYSIS_PATHS skip-analysis=*.autogen.cs
```

Now you can use the \.pvsconfig file with PVS\-Studio utilities:

For CLMonitor\.exe, use the _\-c \(\-\-pvsconfig\)_ flag:

```cpp
CLMonitor.exe analyze ... -c /path/to/.pvsconfig
```

For PVS\-Studio\_Cmd\.exe and pvs\-studio\-dotnet, use the _\-C \(\-\-rulesConfig\)_ flag:

```cpp
PVS-Studio_Cmd.exe -t target.sln -o PVS-Studio.log -C /path/to/.pvsconfig
pvs-studio-dotnet -t target.csproj -o PVS-Studio.log -C /path/to/.pvsconfig
```

For CompilerCommandsAnalyzer\.exe \(Windows\) and pvs\-studio\-analyzer \(Linux, macOS\), use the _\-R \(\-\-rules\-config\)_ flag:

```cpp
CompilerCommandsAnalyzer analyze --cfg /path/to/PVS-Studio.cfg \
                                    -R /path/to/.pvsconfig
```

If you use the _C and C\+\+ Compiler Monitoring UI_ utility, you can specify the path to the \.pvsconfig file when you start monitoring:

![Exclude_paths/image6.png](https://import.viva64.com/docx/blog/Exclude_paths/image6.png)

PVS\-Studio plugins \(for Visual Studio, Rider\) can automatically detect the _\.pvsconfig_ file if it is added to the Solution or project and has the _\.pvsconfig_ extension\. Configuration files added to the Solution have a global scope and apply to all projects of this Solution\. \.pvsconfig files added to the project apply only to the project to which they are added\.

## For CompilerCommandsAnalyzer\.exe and pvs\-studio\-analyzer utilities

If you use the _pvs\-studio\-analyzer\(Linux, macOS\) / CompilerCommandsAnalyzer\.exe \(Windows\)_ cross\-platform utility, you can exclude files from analysis in the following ways\.

### Direct pass of excluded files and directories

You can exclude files from analysis by passing paths to them as launch arguments for _pvs\-studio\-analyzer/CompilerCommandsAnalyzer\.exe_ via the _\-e \(\-\-exclude\-path\)_ flag:

```cpp
pvs-studio-analyzer analyze ... -e /third-party/ \
                                -e /test/        \
                                -e /path/to*/exclude-path
```

Or via the _\-\-analysis\-paths_ flag with the _skip\-analysis_ mode

```cpp
pvs-studio-analyzer analyze ... \
--analysis-paths skip-analysis=/third-party/ \
--analysis-paths skip-analysis=/test/ \
--analysis-paths skip-analysis=/path/to*/exclude-path
```

When specifying a path, you can also use command shell templates \(glob\)\.

### The \*\.cfg configuration file

Create a text file \(for example, _MyProject\.cfg_\)\. Put a list of excluded directories in the text file via the _exclude\-path_ parameter\.

Example:

```cpp
exclude-path=/third-party/
exclude-path=*/test/*
exclude-path=*/lib-*/*
```

Or using the _analysis\-paths_ parameter with the _skip\-analysis_ mode:

```cpp
analysis-paths=skip-analysis=/third-party/
analysis-paths=skip-analysis=*/test/*
analysis-paths=skip-analysis=*/lib-*/*
```

Then run the analysis by passing the path to the configuration file via the _\-\-cfg flag:_

```cpp
pvs-studio-analyzer analyze ... --cfg ./MyProject.cfg
```

You can also add other launch parameters to the configuration file\. Check out this [page](https://pvs-studio.com/en/docs/manual/6615/#cfgFile) to get more information\.