Ignore a directory In PyCharm "Find In FIles" search results
Asked Answered
I

2

6

My question is the same as the one posed here:

Ignore a folder in search results

I'm using PyCharm rather than IntelliJ-IDEA, but I'm guessing that features common to all JetBrains IDEs should work the same. If the accepted answer actually did what is suggested, it would be just what I'm looking for. But it doesn't work for me. It does something interesting, but not what I want.

I have marked directories I don't want searched as "Excluded". My problem is, files aren't excluded from my search results as suggested. The interesting thing is, matched file in the directories I've marked Excluded ARE HILIGHTED to indicate that they were found in one of those directories. So I know I've got everything set up right. The GUI is showing me which files I can myself ignore by way of hilighting them in the search results window. So if it's going that far, surely there must be an option somewhere to exclude them completely. I've looked and looked. I can't find such an option.

Here's a sample result so that you can see what I'm talking about in terms of the hilighting:

enter image description here

Here, what I want is for the first four files shown here to show up but not the remaining eight. Can anyone tell me how to get Excluded files to not show up at all in a Jetbrains Find in Files result window rather than just hilighting them differently? TIA.

Iiette answered 23/8, 2022 at 0:9 Comment(3)
Not 100% sure if this works, but if it works I can post it as an answer... try making a .gitignore file (if you don't already have one), and adding those directories to it. That might cause it to not show up in search. Not 100% sure it will work, but it mightCapeskin
@Capeskin - where would I put this .gitignore file? I have such files throughout my code, but the directories I want to not include aren't in any git repo of mine, and may already include .gitignore files of their own if they are sources for a dependent module that I'm using. So I'm thinking that A) there's no logical place to put a .gitignore file where PyCharm would find it, and B) it could turn out that there is already a conflicting .gitignore file in that location. This issue has nothing to do with Git, so I can't see how a .gitignore file is going to do any good.Iiette
If I don't get an answer here in a few days, I'll fire off a question to the Jetbrains guys. If I get something useful back from them, I'll post it here.Iiette
I
4

I sent off a tech support request to Jetbrains. They got back to me in less than 24 hours (I've always had great response times from them). Here's what they said:

Your understanding is correct -- the excluded directories should not appear in the search result. However, if you just marked the directory as excluded, it may require a project refresh to update the indices. This is done when you reopen the project.

If the issue is still reproduced after reopening a project, there may be an issue with indices, so please try File | Invalidate Caches... | (Check all boxes) Invalidate and Restart.

If that doesn't help as well, please check if the issue is reproduced in a new empty project with a minimal structure to reproduce the issue.

I had already tried reloading my project, then restarting PyCharm, and even rebooting my Mac. None of those things helped. I had thought to rebuild the indexes, but I've got a number of large projects and was concerned that I'd keep hitting delays every time I opened one of them if I cleared out all of PyCharm's caches. But that was about all I had left to try, and since Jetbrains told me to try that, I did.

...and...clearing all PyCharm caches fixed the problem! I no longer see any of the files in Excluded directories when using any of the search modes in the "Find In Files" dialog. To be quite sure that the re-indexing fixed this, before clearing the PyCharm caches, I made a point of closing everything, then opening just the one project I was having trouble with, and then doing a straightforward search. I saw files from Excluded dirs that shouldn't have been there. Then I cleared all the PyCharm caches, and quit and restarted PyCharm. Then I did the exact same search I had done just a few minutes earlier (it took about 5 minutes to re-index the project). The results this time were to only show me what I expected/wanted. The files in Excluded directories were gone from the search results.

Iiette answered 24/8, 2022 at 23:12 Comment(1)
This worked for me as the now excluded folder wasn't marked as excluded prior to indexing.Blandishments
R
2

correct fix is in Settings->Editor->File Types->Ignored Files and Folders

Settings->Editor->File Types->Ignored Files and Folders

Ranie answered 13/9, 2024 at 20:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.