2019-10-21 04:22:28 -04:00
---
title: "fileExists"
linktitle: "fileExists"
date: 2017-08-31T22:38:22+02:00
2021-12-08 02:42:31 -05:00
description: Checks for file or directory existence.
2019-10-21 04:22:28 -04:00
publishdate: 2017-08-31T22:38:22+02:00
2021-12-08 02:42:31 -05:00
lastmod: 2021-11-26
2019-10-21 04:22:28 -04:00
categories: [functions]
menu:
docs:
parent: "functions"
2021-12-08 02:42:31 -05:00
signature: ["os.FileExists PATH","fileExists PATH"]
2019-10-21 04:22:28 -04:00
workson: []
hugoversion:
2021-12-08 02:42:31 -05:00
relatedfuncs: ['os.ReadDir','os.ReadFile','os.Stat']
2019-10-21 04:22:28 -04:00
deprecated: false
aliases: []
---
2021-12-08 02:42:31 -05: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` ]({{< relref "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
{{ os.FileExists "content" }} --> true
{{ os.FileExists "content/news" }} --> true
{{ os.FileExists "content/news/article-1" }} --> false
{{ os.FileExists "content/news/article-1.md" }} --> true
{{ os.FileExists "news" }} --> true
{{ os.FileExists "news/article-1" }} --> false
{{ os.FileExists "news/article-1.md" }} --> true
```