> 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/huong-dan-cac-action/file-and-folder/file-exists.md).

# File exists

Hành động này giúp tool kiểm tra xem một file đã có sẵn trên máy tính hay chưa. Kết quả trả về rất đơn giản: True (nếu thấy file) hoặc False (nếu không thấy).

* Tác dụng: Dùng kết hợp với khối lệnh `If` để xử lý thông minh hơn, tránh trường hợp tool bị lỗi hay dừng đột ngột khi bạn yêu cầu nó mở một file mà thực tế không tồn tại.

🎥 Xem thêm video hướng dẫn: [Tại đây](https://youtu.be/EH7olDLAb9c).

#### Tham số cấu hình:

* File Path: Đường dẫn tuyệt đối dẫn đến file cần kiểm tra trên máy tính (Ví dụ: `D:\data\accounts.txt`).
* Output variable: Tên biến lưu kết quả kiểm tra (`True` hoặc `False`).

#### Ví dụ thực tế: Kiểm tra file cấu hình trước khi chạy kịch bản

Giả sử bạn viết một kịch bản tự động điền thông tin và yêu cầu kịch bản phải đọc dữ liệu từ file `D:\GPM\config.json`. Nếu người dùng quên chưa tạo file này hoặc điền sai đường dẫn, kịch bản chạy đến lệnh đọc file sẽ bị lỗi hệ thống ngay.

Để xử lý an toàn, bạn cấu hình kịch bản như sau:

* Bước 1: Gọi hành động File exists, điền đường dẫn `D:\GPM\config.json` và đặt tên biến đầu ra là `$isFileReady`.
* Bước 2: Dùng khối lệnh If để kiểm tra: `Nếu $isFileReady = False`.
* Bước 3: Nằm bên trong khối If này, bạn gọi hành động Throw với nội dung: `"Lỗi: Bạn chưa tạo file config.json tại ổ D, vui lòng kiểm tra lại!"`.

Kết quả: Kịch bản sẽ tự động kiểm tra trước. Nếu file chưa tồn tại, nó sẽ dừng luồng một cách chủ động và bắn ra cảnh báo màu đỏ trực quan cho bạn biết, thay vì cố chạy tiếp để rồi bị crash kịch bản.

<figure><img src="https://275605936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FN9cKpvJdcLU6FS8VMSTs%2Fuploads%2Fgit-blob-4693a8938e77d89e696d180171fc1fb69ab0238b%2Fimage%20(147).png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gpmautomate.com/huong-dan-cac-action/file-and-folder/file-exists.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
