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

# directoryContents(atPath:)

Returns the directories and files (including symbolic links) contained in a given directory.

```
func directoryContents(atPath path: String) -> [Any]?
```

## Parameters

`path`

A path to a directory.

## Return Value

An array of [`NSString`](/documentation/Foundation/NSString) objects identifying the directories and files (including symbolic links) contained in `path`. Returns an empty array if the directory exists but has no contents. Returns `nil` if the directory specified at `path` does not exist or there is some other error accessing it.

## Discussion

The search is shallow, and therefore does not return the contents of any subdirectories and does not traverse symbolic links in the specified directory. This returned array does not contain strings for the current directory (”`.`”), parent directory (”`..`”), or resource forks (begin with “._”).

### Special Considerations

Because this method does not return error information, it has been deprecated as of OS X v10.5. Use [`contentsOfDirectory(atPath:)`](/documentation/Foundation/FileManager/contentsOfDirectory(atPath:)) instead.

## See Also

[`currentDirectoryPath`](/documentation/Foundation/FileManager/currentDirectoryPath)

The path to the program’s current directory.

[`fileExists(atPath:isDirectory:)`](/documentation/Foundation/FileManager/fileExists(atPath:isDirectory:))

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

[`subpaths(atPath:)`](/documentation/Foundation/FileManager/subpaths(atPath:))

Returns an array of strings identifying the paths for all items in the specified directory.

[`contentsOfDirectory(atPath:)`](/documentation/Foundation/FileManager/contentsOfDirectory(atPath:))

Performs a shallow search of the specified directory and returns the paths of any contained items.

[`enumerator(atPath:)`](/documentation/Foundation/FileManager/enumerator(atPath:))

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.



---

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)