# Filter

**Filter** 对象允许您创建 [文本过滤器](/directory-opus/guan-fang-shou-ce/readme.zh-2/readme.zh-4/textual_filters.zh.md)，其类型与 **查找** 工具以及 **复制** 等命令中使用的类型相同，以控制递归操作。

使用 [**dopusfactory**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/dopusfactory.zh.md)**.Filter** 方法创建新的过滤器对象。拥有 **Filter** 对象后，您可以：

* 使用 [**item**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/item.zh.md)**.MatchFilter** 方法查看文件或文件夹是否与过滤器匹配。
* 使用 [**command**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/command.zh.md)**.SetFilter** 方法将过滤器应用于命令。

| 属性名称      | 返回类型                                                                                                                         | 说明                                         |
| --------- | ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| lasterror | *object:*[**filterparseerror**](/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/filterparseerror.zh.md) | 如果 *valid* 返回 **False**，则可以使用此属性发现有关错误的信息。 |
| valid     | *bool*                                                                                                                       | 如果过滤器创建成功（即解析过滤器文本时未遇到错误），则返回 **True**。    |

| 方法名称  | **参数**                                                                                     | 返回类型   | 说明                                                                                                                                                                                                                                                                                                                                                                                                               |
| ----- | ------------------------------------------------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Add   | <p>\<string:clause><br>或 \<object:<strong>Filter</strong>><br>\[\<string:conjunction>]</p> | *bool* | <p>将子句添加到过滤器。如果以字符串形式提供，则将解析该子句，如果解析成功，则该方法返回 <strong>True</strong>。如果解析失败，请使用 <strong>lasterror</strong> 属性找出原因。或者，您可以添加另一个 <strong>Filter</strong> 对象。</p><p><em>clause</em> 字符串必须是完全形成的 <a href="/pages/jP9wJR1ruQUR8Q9eBkDA">文本过滤器</a> 子句。例如，<code>size match > 2 mb</code></p><p>可选的 <em>conjunction</em> 字符串允许您选择是通过 <strong>and</strong> 还是 <strong>or</strong> 连接子句。如果未指定，则默认为 <strong>and</strong>。</p> |
| Clear | *none*                                                                                     | *none* | 清除过滤的内容。                                                                                                                                                                                                                                                                                                                                                                                                         |
| Set   | <p>\<string:clause><br>或 \<object:<strong>Filter</strong>></p>                             | *bool* | 使用字符串或现有 **Filter** 对象的内容初始化过滤器。如果以字符串形式提供，则将解析该子句，如果解析成功，则该方法返回 **True**。如果解析失败，请使用 **lasterror** 属性找出原因。                                                                                                                                                                                                                                                                                                       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/filter.zh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
