> 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-write-all-text.md).

# File write all text

文件写入所有文本是一个用于将字符串写入计算机上`.txt`格式文件的操作。

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

该操作具有特殊的运行机制（覆盖和自动创建）：

* 如果文件不存在：系统将自动根据指定路径创建新的`.txt`文件并写入内容。
* 如果文件已存在：系统将清除文件中所有旧内容并覆盖写入新内容。

#### 配置参数：

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

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

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

* 配置方法：
  * 调用文件写入所有文本操作。
  * 文件路径：填写`D:\GPM\report.txt`。
  * 文本：填写内容：`"--- 今天的脚本运行日志 ---"`。
* 结果：
  * 如果`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/cao-zuo-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.
