2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: os.FileExists
linkTitle: fileExists
description: Reports whether the file or directory exists.
2019-10-21 04:22:28 -04:00
categories: [functions]
2023-10-20 03:42:39 -04:00
keywords: []
2019-10-21 04:22:28 -04:00
menu:
docs:
2023-05-22 10:43:12 -04:00
parent: functions
2023-10-20 03:42:39 -04:00
function:
aliases: [fileExists]
returnType: bool
signatures: [os.FileExists PATH]
relatedFunctions:
- os.FileExists
- os.Getenv
- os.ReadDir
- os.ReadFile
- os.Stat
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-08-07 04:35:12 -04:00
{{ 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
2021-12-08 02:42:31 -05:00
```