> 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).

# 文件写入所有文本

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

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

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

#### 配置参数：

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

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

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

* 配置方式：
  * 调用文件写入所有文本操作。
  * 文件路径：填写`D:\GPM\report.txt`。
  * 文本：填写内容：`"--- 今天的脚本运行日志 ---"`。
* 结果：
  * 如果`report.txt`文件尚不存在，系统将在`D:\GPM\`目录下自动创建此文件。
  * 如果文件从昨天开始已经存在（包含旧内容），系统将清除所有旧内容，将文件变为空文件，然后写入行文本`"--- 今天的脚本运行日志 ---"`。


---

# 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.
