> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/file-and-folder/file-exists.md).

# 文件存在

此操作帮助工具检查计算机上是否已存在文件。返回结果非常简单：True（如果找到文件）或False（如果未找到）。

* 作用：与`If`语句块结合使用，以更智能地处理，避免工具在您要求它打开一个实际上不存在的文件时出现错误或突然停止。

#### 配置参数：

* 文件路径：指向计算机上需要检查的文件的绝对路径（例如：`D:\data\accounts.txt`）。
* 输出变量：保存检查结果的变量名称（`True`或`False`）。

#### 实际示例：在运行脚本之前检查配置文件

假设您编写了一个自动填写信息的脚本，并要求脚本从文件`D:\GPM\config.json`读取数据。如果用户忘记创建此文件或输入错误的路径，脚本在读取文件的命令处将立即出现系统错误。

为了安全处理，您可以按如下方式配置脚本：

* 步骤1：调用文件存在操作，填写路径`D:\GPM\config.json`并将输出变量命名为`$isFileReady`。
* 步骤2：使用If语句块进行检查：`如果 $isFileReady = False`。
* 步骤3：在此If语句块内，调用Throw操作，内容为：`"错误：您尚未在D盘创建config.json文件，请检查！"`。

结果：脚本将自动进行检查。如果文件不存在，它将主动停止流程并发出红色警告，提醒您，而不是继续运行导致脚本崩溃。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/file-and-folder/file-exists.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
