| 1 |
--- |
| 2 |
title: os.FileExists |
| 3 |
description: Reports whether the file or directory exists. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [fileExists] |
| 9 |
returnType: bool |
| 10 |
signatures: [os.FileExists PATH] |
| 11 |
aliases: [/functions/fileexists] |
| 12 |
--- |
| 13 |
|
| 14 |
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`][]. A leading path separator (`/`) is optional. |
| 15 |
|
| 16 |
With this directory structure: |
| 17 |
|
| 18 |
```tree |
| 19 |
content/ |
| 20 |
├── about.md |
| 21 |
├── contact.md |
| 22 |
└── news/ |
| 23 |
├── article-1.md |
| 24 |
└── article-2.md |
| 25 |
``` |
| 26 |
|
| 27 |
The function returns these values: |
| 28 |
|
| 29 |
```go-html-template |
| 30 |
{{ fileExists "content" }} → true |
| 31 |
{{ fileExists "content/news" }} → true |
| 32 |
{{ fileExists "content/news/article-1" }} → false |
| 33 |
{{ fileExists "content/news/article-1.md" }} → true |
| 34 |
{{ fileExists "news" }} → true |
| 35 |
{{ fileExists "news/article-1" }} → false |
| 36 |
{{ fileExists "news/article-1.md" }} → true |
| 37 |
``` |
| 38 |
|
| 39 |
[`contentDir`]: /configuration/all/#contentdir |