<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileManager/fileExists(atPath:isDirectory:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)fileExistsAtPath:isDirectory:"
  },
  "title" : "fileExists(atPath:isDirectory:)"
}
-->

# fileExists(atPath:isDirectory:)

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

```
func fileExists(atPath path: String, isDirectory: UnsafeMutablePointer<ObjCBool>?) -> Bool
```

## Parameters

`path`

The path of a file or directory. If `path` begins with a tilde (`~`), it must first be expanded with [`expandingTildeInPath`](/documentation/Foundation/NSString/expandingTildeInPath), or this method will return <doc://com.apple.documentation/documentation/Swift/false>.

`isDirectory`

Upon return, contains <doc://com.apple.documentation/documentation/Swift/true> if `path` is a directory or if the final path element is a symbolic link that points to a directory; otherwise, contains <doc://com.apple.documentation/documentation/Swift/false>. If `path` doesn’t exist, this value is undefined upon return. Pass `NULL` if you do not need this information.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if a file at the specified path exists, or <doc://com.apple.documentation/documentation/Swift/false> if the file’s does not exist or its existence could not be determined.

## Discussion

If the file at `path` is inaccessible to your app, perhaps because one or more parent directories are inaccessible, this method returns <doc://com.apple.documentation/documentation/Swift/false>. If the final element in `path` specifies a symbolic link, this method traverses the link and returns <doc://com.apple.documentation/documentation/Swift/true> or <doc://com.apple.documentation/documentation/Swift/false> based on the existence of the file at the link destination.

If you need to further determine whether `path` is a package, use the <doc://com.apple.documentation/documentation/AppKit/NSWorkspace/isFilePackage(atPath:)> method of <doc://com.apple.documentation/documentation/AppKit/NSWorkspace>.

The following example code gets an array that identifies the fonts in the user’s fonts directory:

```objc
NSArray *subpaths;
BOOL isDir;
 
NSArray *paths = NSSearchPathForDirectoriesInDomains
                     (NSLibraryDirectory, NSUserDomainMask, YES);
 
if ([paths count] == 1) {
 
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSString *fontPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Fonts"];
 
    if ([fileManager fileExistsAtPath:fontPath isDirectory:&isDir] && isDir) {
        subpaths = [fileManager subpathsAtPath:fontPath];
// ...
```

> 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](https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585) in [Secure Coding Guide](https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Introduction.html#//apple_ref/doc/uid/TP40002415).

## See Also

[`checkResourceIsReachableAndReturnError(_:)`](/documentation/Foundation/NSURL/checkResourceIsReachableAndReturnError(_:))

Returns whether the resource pointed to by a file URL can be reached.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)