简体   繁体   English

从 Eclipse 搜索中排除文件夹

[英]Exclude folders from Eclipse search

有没有办法从 Eclipse 中的搜索中排除某些文件夹(及其所有子文件夹)?

The quick and dirty way:快速而肮脏的方式:

Right click on a folder, go to properties, and mark a folder as derived.右键单击文件夹,转到属性,然后将文件夹标记为派生文件夹。 Derived entities are excluded from searching by default.默认情况下从搜索中排除派生实体。 The problem with this approach is that Eclipse "forgets" that the folder is derived if you delete it (either from within Eclipse or externally, followed by refreshing the project tree).这种方法的问题在于,如果您删除文件夹(从 Eclipse 内部或外部,然后刷新项目树) ,Eclipse 会“忘记”该文件夹是派生的 Like so often with Eclipse, this is a long-standing bug (10 years in this case) which still applies to the current version (4.6 Neon at the time of writing).与 Eclipse 一样,这是一个长期存在的错误(在这种情况下为 10 年),它仍然适用于当前版本(撰写本文时为 4.6 Neon)。

The safe way:安全的方法:

Create a working set including only those entities you want searched and search only within that working set.创建一个工作集,仅包含您要搜索的那些实体,并仅在该工作集内进行搜索。 See Dave Ray's answer for details on this procedure.有关此过程的详细信息,请参阅Dave Ray 的回答

Here is what works for me (I'm using Helios - maybe this way was not available when this question was originally asked?)这是对我有用的方法(我正在使用 Helios - 也许最初问这个问题时这种方式不可用?)

  • Go to Project -> Properties -> Resource Filters.转到项目 -> 属性 -> 资源过滤器。
  • Click Add .单击添加
  • Choose Filter type : Exclude all选择过滤器类型排除所有
  • Choose Applies to : Folders ;选择适用于文件夹 check All children (recursive) .检查所有孩子(递归)
  • In the Attributes, choose Name , Matches , .svn (for example).在 Attributes 中,选择NameMatches.svn (例如)。

(Actually, I'm using .* to filter out .svn, .hg etc. in one go.) (实际上,我正在使用.*一次性过滤掉 .svn、.hg 等。)

After okay'ing the project properties dialog, these directories won't come up in search any more.确定项目属性对话框后,这些目录将不再出现在搜索中。 In fact, Eclipse is so kind as to automatically update existing search results windows and remove all matches which are now filtered out.事实上,Eclipse 非常友好,可以自动更新现有的搜索结果窗口并删除所有现在被过滤掉的匹配项。

I could imagine that marking resources derived might cause problems in other areas.我可以想象,派生的标记资源可能会导致其他领域的问题。 Instead, create a working set with the folders you want to include in the search:相反,使用要包含在搜索中的文件夹创建一个工作集:

  • Open Search dialog ( Ctrl + H )打开搜索对话框( Ctrl + H
  • Change search scope to Working Set将搜索范围更改为工作集
  • Click Choose ...点击选择...
  • Click New to create a new Working Set with the what you want searched (or Add All and then remove the ones you want filtered单击新建以使用您要搜索的内容创建新的工作集(或全部添加,然后删除要过滤的内容)
  • Right click on your project右键单击您的项目
  • Select Properties选择Properties
  • Select Resource -> Resource filters选择Resource -> Resource filters
  • Click Add filter单击Add filter
  • Choose the following settings:选择以下设置:
    • Exclude all排除所有
    • Files and folders文件和文件夹
    • All children (recursive)所有孩子(递归)
  • Change Name for Project Relative Path更改Project Relative Path Name
  • Fill input text with (bin$|bin/.*|build/.*|build$) (replace bin and build by the names of the folders you want to exclude)(bin$|bin/.*|build/.*|build$)填充输入文本(用要排除的文件夹的名称替换binbuild
  • Tick Regular expression勾选Regular expression

Hit OK and then Apply.点击确定,然后应用。

Disclaimer免责声明

This builds on @atzz's answer, which helped me figure this out.这是建立在@atzz 的回答之上的,它帮助我解决了这个问题。 However while it did answer the question of how to exclude certain files, it didn't answer the question of how to exclude certain folders.然而,虽然它确实回答了如何排除某些文件的问题,但它没有回答如何排除某些文件夹的问题。

The best quick and dirty way in Eclipse Juno: Eclipse Juno 中最好的快速和肮脏的方法:

  1. Right click on the folder .右键单击文件夹
  2. Go to Properties.转到属性。
  3. Go to C/C++ Build.转到 C/C++ 构建。
  4. Check "Exclude resource from build".选中“从构建中排除资源”。
  5. Click in OK button.单击确定按钮。
  6. Right click on the project .右键单击该项目
  7. Go to Index.转到索引。
  8. Click Rebuild.单击重建。
  9. Relax!放松!

Excluding a folder or file from being searched in Eclipse排除在 Eclipse 中搜索的文件夹或文件

1 Right-click on the file/folder.
3 Click on the "Properties" option.
4 Select the "Resource" option.
5 Place a check next to the "Derived" attribute.

Hope is help.希望是帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM