> 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/action-shi-yong-zhi-nan/file-and-folder/file-write-all-text.md).

# File write all text

File write all text 是用于将一段文本字符串写入计算机上 `.txt` 格式文件的操作。

🎥 查看更多教程视频：[点击这里](https://youtu.be/EH7olDLAb9c)。

此操作具有特殊的运行机制（覆盖并自动创建新文件）：

* 如果文件不存在：系统将自动在指定路径下创建新的 `.txt` 文件，然后写入内容。
* 如果文件已存在：系统将清空文件中现有的全部旧内容，并覆盖写入新内容。

#### 配置参数：

* File Path：要写入数据的 `.txt` 文件的绝对路径（例如：`D:\GPM\status.txt`）。
* Text：您想写入文件的原始文本内容（或包含文本的变量）。

#### 实际示例：自动创建新的状态报告文件

假设您在每天开始时运行一个与新账户互动的脚本。您希望脚本自动清空（或新建）一个位于 D 盘、名为 `report.txt` 的文本文件，然后在其中写入第一行欢迎语，以便为今天的日志记录做准备。

* 配置方法：
  * 调用 File write all text 操作。
  * File Path：填写 `D:\GPM\report.txt`。
  * Text：填写内容：`"--- 今天的脚本运行日志 ---"`。
* 结果：
  * 如果尚无 `report.txt` 文件，系统会自动在 `D:\GPM\` 目录下创建该文件。
  * 如果文件是昨天已存在的（含有大量旧内容），系统会将旧内容彻底清空，使文件变为空白文件，然后写入 `"--- 今天的脚本运行日志 ---"` 这行文字。

<figure><img src="/files/YWdkKIX31dtwd2liKlin" alt=""><figcaption></figcaption></figure>


---

# 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/action-shi-yong-zhi-nan/file-and-folder/file-write-all-text.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.
