# Excluding directories and files from the Snyk Code CLI test

When you test a repository via the CLI, you can exclude certain directories and files from the Snyk Code test by using the `snyk ignore --file-path` command. When running this command, the `.snyk` file is created automatically in your repository, containing the directory's name or file you specified for exclusion.

{% hint style="info" %}

* You can also manually create the `.snyk` file in your repository, and use it to exclude directories and files from the CLI test. For more information about the manual creation of the `.snyk` file, see [Excluding directories and files from the import process.](https://docs.snyk.io/products/snyk-code/getting-started-with-snyk-code/activating-snyk-code-using-the-web-ui/step-3-importing-repositories-to-snyk-for-the-snyk-code-testing/excluding-directories-and-files-from-the-import-process)
* The `snyk ignore --file-path` command does NOT ignore specific vulnerability issues. It ONLY excludes directories and files from the Snyk Code test.
* Consider excluding directories and files only if you do not publish or compile them into production. If a trace goes through an excluded file or directory with existing vulnerabilities, Snyk might miss potential issues.
  {% endhint %}

## **To exclude directories and files from the Snyk Code test:**

1\. In the terminal, change the directory to the folder you want to test.

**Note**: The `snyk ignore --file-path` command applies only to the folder (and its sub-folders and files) from which you are running it.

2\. In the terminal, enter the following:

```
snyk ignore --file-path=<directory_or_file>
```

Where:

* `directory_or_file` - the name of the directory or file you want to exclude from the test. For example, `db.js`.

The `.snyk` file is created in the root folder, containing the directory/file that was specified for exclusion.

**Note**: The `.snyk` file is created as a hidden file. If you do not see it in your root folder, use the **View hidden files** option on your machine.

3\. \[Optional] To specify several directories or files for exclusion, enter:

```
snyk ignore --file-path=<directory1_or_file1> && snyk ignore --file-path=<directory2_or_file2> && snyk ignore --file-path=<directory3_or_file3>
```

From now on, when you will run the `snyk code test` command from the selected folder, the specified directories or files will be excluded from the test.

## Re-include excluded files in test dir\\

To re-include in the test directories/files that were excluded from it, manually edit or delete the `.snyk` file.

1\. In the **snyk-goof-master** folder, 12 issues were found in 3 different files: **app.js**, **db.js**, and **routes/index.js**:

![](https://2533899886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MdwVZ6HOZriajCf5nXH%2Fuploads%2FbWgNq5OUfpxQue5CGR8t%2Fsnyk%20Code%20-%20CLI%20-%20snyk%20code%20test%20-%20Exclusion%20-%20before%20-2.png?alt=media\&token=87b5d3b8-a730-4d6b-8627-4ab1e9573def)

2\. To exclude the **app.js** and **db.js** files, and display only issues that are discovered in the **routes/index.js** file, we enter:

```
snyk ignore --file-path=app.js && snyk ignore --file-path=db.js
```

![](https://2533899886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MdwVZ6HOZriajCf5nXH%2Fuploads%2FbtCS5fXg31tR0xJxGD35%2Fsnyk%20Code%20-%20CLI%20-%20snyk%20code%20test%20-%20Exclusion%20-%20Example%20command.png?alt=media\&token=f0245093-6850-49b0-a0c2-0dcb6d0e6b03)

3\. When the `snyk ignore` command is entered, the `.snyk` file is created automatically in the **snyk-goof-master** folder:

![](https://2533899886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MdwVZ6HOZriajCf5nXH%2Fuploads%2FZhKarccUlcsFOr6AIHZk%2Fsnyk%20Code%20-%20CLI%20-%20snyk%20code%20test%20-%20Exclusion%20-%20Example%20-%20.snyk%20file.png?alt=media\&token=ccdadf21-7307-41d7-94d2-28a3f651cc63)

This `.snyk` file contains the files we specified for exclusion:

![](https://2533899886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MdwVZ6HOZriajCf5nXH%2Fuploads%2FOJTWDt9H556YtFx2RET9%2Fsnyk%20Code%20-%20CLI%20-%20snyk%20code%20test%20-%20Exclusion%20-%20Example%20-%20.snyk%20file%20-%20content.png?alt=media\&token=e5f17252-c180-40a5-a314-fc568d756091)

4\. When we run the test again, the **app.js** and **db.js** files are excluded from the test, and we receive only the issues that were found in the **routes/index.js** file:

![](https://2533899886-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MdwVZ6HOZriajCf5nXH%2Fuploads%2FJBKboLbSg5zqfcOa2YpB%2Fsnyk%20Code%20-%20CLI%20-%20snyk%20code%20test%20-%20Exclusion%20-%20after%20-%202.png?alt=media\&token=4c7a48e0-52fe-47b4-b5c0-ecde16d38376)
