I need to do a find in files. I want to ignore or exclude generated files, like JAX-WS artifacts or classes in target folders. How can I tell IDEA to exclude these files from the find?
-
7Yes! And they always put the generated results on TOP! Sheesh! – SMBiggs Oct 16 '15 at 16:28
5 Answers
Create a Custom Scope defining the set of files to include/exclude from your search.
- CTRL+SHIFT+F for the Find in Path dialog. (Mac users press command+shift+F)
Under Scope select Custom.
Choose a scope from the drop down list or create a Custom Scope by clicking on the ... button to the right of dropdown.
- In the dialog that appears, click on the + button and select Local
- On the right pane you can Include and Exclude individual files and Recursively include or exclude all files beneath a folder.
Now when you use Find in Path, use your custom scope to restrict which files are searched.
I suspect from the reference to Find in Files in your question that these instructions may not apply to your version but it is useful to know that this functionality exists and there is always the 30 day evaluation version.

- 7,958
- 8
- 39
- 51
-
4That works. Thanks. I had hoped there was some setting or checkbox I had overlooked to the effect of "ignore generated files". – Freiheit May 21 '13 at 21:18
-
Excellent! I was worried that I was describing steps that didn't appear in your version. – Rob Kielty May 21 '13 at 21:22
-
1@Freiheit You might be able to have your project ignore the generated files too, which would exclude them from searches and the like by default everywhere (unless you like seeing or need your generated files in IntelliJ, of course). – ajp15243 May 21 '13 at 21:28
-
3
-
1For reference, these steps work the exact same in IntelliJ Ultimate 13. – kurtzbot Aug 01 '14 at 17:17
-
1Thanks! Still works in 2016.2.2. Very helpful when web-files is copied by grunt/nodejs to a new location. Very frustrating to see duplicates. – Jonathan Aug 29 '16 at 08:33
-
1You can use this pattern to filter out classes generated by dagger and butterknife: `!file:*InjectAdapter.java&&!file:*ModuleAdapter.java&&!file:*_ViewBinding.java` – B W Jul 07 '17 at 14:59
-
This info oudated. Please update for new Intellij Idea version – Vitalii Diravka Aug 16 '21 at 03:59
I know this is late to the party, and Rob's answer is a decent one. I'd just like to add the following alternative though: if you chose the Custom
scope (as in Rob's answer), then leave the selection at Project Files
, this will make IntelliJ search a bit more selectively than by default. I don't know what the exact differences are, but of particular interest is that if you mark a directory as Excluded
either using the Modules
tab in the Project Structure
settings, or by right-clicking on a directory and selecting Mark Directory As
-> Excluded
.
If the files you want to exclude are in a single or relatively few directories so you can easily manually set up these exclusion rules, this is a really nice way of getting the same result without needing to configure a custom scope.
I tested this in IntelliJ Ultimate 14.1.4. I have no idea how it behaves in other versions, but I suspect most of v14 at least will behave the same.

- 5,628
- 1
- 29
- 55
-
I marked a directory excluded by mistake, how to include it again. The context option "Mark Directory As" is no longer visible for that directory. – coding_idiot Sep 02 '15 at 01:58
-
2@coding_idiot `Mark Directory As` is still visible to me when I do that (the option to choose is then `Cancel Exclusion`). If that for some reason doesn't work for you, you should be able to do the same thing by opening the `Module` settings (`Project Settings` -> `Modules` -> `
`). In that dialogue all excluded folders should be listed on the right with an `x` next to it to stop the exclusion. – Vala Sep 02 '15 at 15:17 -
Related: [IDEA-87037 – Usability: Find in Path -- NOT in Whole project](https://youtrack.jetbrains.com/issue/IDEA-87037) – Piotr Dobrogost Sep 22 '15 at 07:23
You can also put the search file filter starting with !
sign to exclude.
Example to search code not in Test Java files:
!*Test.java
If you have a few types of files you can separate with ,
sign.
Example to search in Kotlin and Groovy files only:
*.kt,*.groovy
This might be also helpful.

- 1,448
- 19
- 23
IntelliJ Skip generated files pattern during searching
I use the next pattern to exclude generated files
!file:*intermediates*/&&!file:*generated*/&&!lib:*..*

- 29,217
- 8
- 193
- 205
I use this filter to create a custom scope to exclude the target folder in play framework applications:
(src:*..*||test:*..*)&&!file:target//*
Also, this is the language reference for the scope definition language: https://www.jetbrains.com/help/idea/scope-language-syntax-reference.html

- 3,269
- 4
- 38
- 51