I\'m searching for a string and getting matches in a source folder, and a build folder (file in source gets copied to build during build).
I do not need the build fo
Right-Click on directory -> Mark Directory as -> Excluded.
A number of answers work well for older versions of IntelliJ, but in 2020.2, and possibly other recent versions, I keep seeing excluded folders in my search results. In my case: node_modules.
I found something that does work, though. For javascript projects, at least. There might be something similar available for other languages.
Hopefully this works, but if it doesn't, and you're using Javascript, continue:
Whether this is a good idea remains to be seen; IntelliJ doesn't merely exclude them from your search, but from all its code parsing, which means it might not recognise imports from that directory either. For me it seems to work fine at the moment, but I give no guarantees. Try it, but remember how to revert this.
It's an ugly work around. IntelliJ clearly needs a better way to exclude directories from searches.
In Intellij 15, to exclude a folder just do this:
in the Project window, select the folder then right click and choose "Mark Directory As" > "Excluded"
Article last modified: 08 June 2020
Exclude files and folders by name patterns
Ctrl+Alt+S, click Directories .*.min.js or lib. Use semicolons as separators.
Source: https://www.jetbrains.com/help/phpstorm/excluding-files-from-project.html
By defining a Scope when searching, you can include/exclude arbitrary files/folders from that scope.
One way to achieve your requirement (excluding files and folders from a search) is to define a custom scope. This is specifically useful because sometimes you just want to exclude a folder from your search and not from the whole project.
Follow these steps:
Edit -> Find -> Find in path or press Ctrl+Shift+F.
Choose Custom in the Scope section and then choose <unknown scope>

+ button to add a new local custom scope

include recursively and then exclude one by one by choosing exclude or exclude recursively.
Note that you can even include or exclude libraries your project is dependent on.
Scope section in Find in Path dialog.You can check the JetBrains docs on Scopes for more info. Scopes can be used not only when searching but also in a bunch of other use cases in IntelliJ IDEA.
You can use Patterns to define a scope which makes them even more powerful and future proof.
using patterns is another way to exclude files and folders. For instance
file:src/main/java//*&&!file:src/main/java/my//* will exclude all files in my folder.

If you are searching for usages, open the "Find Usages Settings..." , by default Ctrl+Alt+Shift+F7, to narrow down the scope from "All files" to "Project files".