---
title: "fileExists(atPath:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filemanager/fileexists(atpath:)"
---

# fileExists(atPath:)

Returns a Boolean value that indicates whether a file or directory exists at a specified path.

## Declaration

```swift
func fileExists(atPath path: String) -> Bool
```

## Parameters

- `path`: The path of the file or directory. If path begins with a tilde (~), it must first be expanded with doc://com.apple.foundation/documentation/Foundation/NSString/expandingTildeInPath; otherwise, this method returns doc://com.apple.documentation/documentation/Swift/false. App Sandbox does not restrict which path values may be passed to this parameter.

## Return Value

Return Value true if a file at the specified path exists, or false if the file does not exist or its existence could not be determined.

## Discussion

Discussion If the file at path is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns false. If the final element in path specifies a symbolic link, this method traverses the link and returns true or false based on the existence of the file at the link destination. note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file-system race conditions, see Race Conditions and Secure File Operations in Secure Coding Guide.

## See Also

### Related Documentation

- [checkResourceIsReachableAndReturnError(_:)](foundation/nsurl/checkresourceisreachableandreturnerror(_:).md)

### Determining access to files

- [fileExists(atPath:isDirectory:)](foundation/filemanager/fileexists(atpath:isdirectory:).md)
- [isReadableFile(atPath:)](foundation/filemanager/isreadablefile(atpath:).md)
- [isWritableFile(atPath:)](foundation/filemanager/iswritablefile(atpath:).md)
- [isExecutableFile(atPath:)](foundation/filemanager/isexecutablefile(atpath:).md)
- [isDeletableFile(atPath:)](foundation/filemanager/isdeletablefile(atpath:).md)
