2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: os.FileExists
description: Reports whether the file or directory exists.
2023-12-04 09:14:18 -05:00
categories: []
2023-10-20 03:42:39 -04:00
keywords: []
2023-12-04 09:14:18 -05:00
action:
2023-10-20 03:42:39 -04:00
aliases: [fileExists]
2023-12-04 09:14:18 -05:00
related:
- functions/os/Getenv
- functions/os/ReadDir
- functions/os/ReadFile
- functions/os/Stat
2023-10-20 03:42:39 -04:00
returnType: bool
signatures: [os.FileExists PATH]
aliases: [/functions/fileexists]
2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
2023-05-22 10:43:12 -04:00
The `os.FileExists` function attempts to resolve the path relative to the root of your project directory. If a matching file or directory is not found, it will attempt to resolve the path relative to the [`contentDir` ](/getting-started/configuration#contentdir ). A leading path separator (`/`) is optional.
2019-10-21 04:22:28 -04:00
2021-12-08 02:42:31 -05:00
With this directory structure:
2019-10-21 04:22:28 -04:00
2021-12-08 02:42:31 -05:00
```text
content/
├── about.md
├── contact.md
└── news/
├── article-1.md
└── article-2.md
2019-10-21 04:22:28 -04:00
```
2021-12-08 02:42:31 -05:00
The function returns these values:
```go-html-template
2023-12-04 09:14:18 -05:00
{{ fileExists "content" }} → true
{{ fileExists "content/news" }} → true
{{ fileExists "content/news/article-1" }} → false
{{ fileExists "content/news/article-1.md" }} → true
{{ fileExists "news" }} → true
{{ fileExists "news/article-1" }} → false
{{ fileExists "news/article-1.md" }} → true
2021-12-08 02:42:31 -05:00
```