<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager"
  },
  "title" : "FileManager"
}
-->

# FileManager

A convenient interface to the contents of the file system, and the primary means of interacting with it.

```
class FileManager
```

## Overview

A file manager object lets you examine the contents of the file system and make changes to it. The [`FileManager`](/documentation/Foundation/FileManager) class provides convenient access to a shared file manager object that is suitable for most types of file-related manipulations. A file manager object is typically your primary mode of interaction with the file system. You use it to locate, create, copy, and move files and directories. You also use it to get information about a file or directory or change some of its attributes.

When specifying the location of files, you can use either [`NSURL`](/documentation/Foundation/NSURL) or [`NSString`](/documentation/Foundation/NSString) objects. The use of the [`NSURL`](/documentation/Foundation/NSURL) class is generally preferred for specifying file-system items because URLs can convert path information to a more efficient representation internally. You can also obtain a bookmark from an [`NSURL`](/documentation/Foundation/NSURL) object, which is similar to an alias and offers a more sure way of locating the file or directory later.

If you are moving, copying, linking, or removing files or directories, you can use a delegate in conjunction with a file manager object to manage those operations. The delegate’s role is to affirm the operation and to decide whether to proceed when errors occur. In macOS 10.7 and later, the delegate must conform to the [`FileManagerDelegate`](/documentation/Foundation/FileManagerDelegate) protocol.

In iOS 5.0 and later and in macOS 10.7 and later, [`FileManager`](/documentation/Foundation/FileManager) includes methods for managing items stored in iCloud. Files and directories tagged for cloud storage are synced to iCloud so that they can be made available to the user’s iOS devices and Macintosh computers. Changes to an item in one location are propagated to all other locations to ensure the items stay in sync.

### Sync control

A [package](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/DocumentPackages/DocumentPackages.html#//apple_ref/doc/uid/10000123i-CH106-SW1) is a directory that the system presents as a single file to the person using the device. Apps with documents that contain multiple files can use packages to manage contents like media assets. In iOS 26 and macOS 26 and later, [`FileManager`](/documentation/Foundation/FileManager) introduces methods for controlling how a file provider syncs these items. By pausing sync when your app opens a package and resuming when it closes, your app can prevent the file provider from changing the contents of the package in unexpected ways, which potentially leaves the document in an inconsistent state. You can also use this pause and resume API on regular “flat” files.

### Threading considerations

The methods of the shared [`FileManager`](/documentation/Foundation/FileManager) object can be called from multiple threads safely. However, if you use a delegate to receive notifications about the status of move, copy, remove, and link operations, you should create a unique instance of the file manager object, assign your delegate to that object, and use that file manager to initiate your operations.

## Topics

### Creating a file manager

[`init(authorization:)`](/documentation/Foundation/FileManager/init(authorization:))

Initializes a file manager object that is authorized to perform privileged file system operations.

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

The shared file manager object for the process.

### Accessing user directories

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

The home directory for the current user.

[`NSHomeDirectory()`](/documentation/Foundation/NSHomeDirectory())

Returns the path to either the user’s or application’s home directory, depending on the platform.

[`NSUserName()`](/documentation/Foundation/NSUserName())

Returns the logon name of the current user.

[`NSFullUserName()`](/documentation/Foundation/NSFullUserName())

Returns a string containing the full name of the current user.

[`homeDirectory(forUser:)`](/documentation/Foundation/FileManager/homeDirectory(forUser:))

Returns the home directory for the specified user.

[`NSHomeDirectoryForUser(_:)`](/documentation/Foundation/NSHomeDirectoryForUser(_:))

Returns the path to a given user’s home directory.

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

The temporary directory for the current user.

[`NSTemporaryDirectory()`](/documentation/Foundation/NSTemporaryDirectory())

Returns the path of the temporary directory for the current user.

### Locating system directories

[`url(for:in:appropriateFor:create:)`](/documentation/Foundation/FileManager/url(for:in:appropriateFor:create:))

Locates and optionally creates the specified common directory in a domain.

[`urls(for:in:)`](/documentation/Foundation/FileManager/urls(for:in:))

Returns an array of URLs for the specified common directory in the requested domains.

[`NSSearchPathForDirectoriesInDomains(_:_:_:)`](/documentation/Foundation/NSSearchPathForDirectoriesInDomains(_:_:_:))

Creates a list of directory search paths.

[`NSOpenStepRootDirectory()`](/documentation/Foundation/NSOpenStepRootDirectory())

Returns the root directory of the user’s system.

### Locating application group container directories

[`containerURL(forSecurityApplicationGroupIdentifier:)`](/documentation/Foundation/FileManager/containerURL(forSecurityApplicationGroupIdentifier:))

Returns the container directory associated with the specified security application group identifier.

  <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.security.application-groups>

### Discovering directory contents

[`contentsOfDirectory(at:includingPropertiesForKeys:options:)`](/documentation/Foundation/FileManager/contentsOfDirectory(at:includingPropertiesForKeys:options:))

Performs a shallow search of the specified directory and returns URLs for the contained items.

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

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

[`enumerator(at:includingPropertiesForKeys:options:errorHandler:)`](/documentation/Foundation/FileManager/enumerator(at:includingPropertiesForKeys:options:errorHandler:))

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

[`enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:`](/documentation/Foundation/NSFileManager/enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:)

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

[`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.

[`FileManager.DirectoryEnumerator`](/documentation/Foundation/FileManager/DirectoryEnumerator)

An object that enumerates the contents of a directory.

[`mountedVolumeURLs(includingResourceValuesForKeys:options:)`](/documentation/Foundation/FileManager/mountedVolumeURLs(includingResourceValuesForKeys:options:))

Returns an array of URLs that identify the mounted volumes available on the device.

[`FileManager.VolumeEnumerationOptions`](/documentation/Foundation/FileManager/VolumeEnumerationOptions)

Options for enumerating mounted volumes with the [`mountedVolumeURLs(includingResourceValuesForKeys:options:)`](/documentation/Foundation/FileManager/mountedVolumeURLs(includingResourceValuesForKeys:options:)) method.

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

Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.

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

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

### Creating and deleting items

[`createDirectory(at:withIntermediateDirectories:attributes:)`](/documentation/Foundation/FileManager/createDirectory(at:withIntermediateDirectories:attributes:))

Creates a directory with the given attributes at the specified URL.

[`createDirectory(atPath:withIntermediateDirectories:attributes:)`](/documentation/Foundation/FileManager/createDirectory(atPath:withIntermediateDirectories:attributes:))

Creates a directory with given attributes at the specified path.

[`createFile(atPath:contents:attributes:)`](/documentation/Foundation/FileManager/createFile(atPath:contents:attributes:))

Creates a file with the specified content and attributes at the given location.

[`removeItem(at:)`](/documentation/Foundation/FileManager/removeItem(at:))

Removes the file or directory at the specified URL.

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

Removes the file or directory at the specified path.

[`trashItem(at:resultingItemURL:)`](/documentation/Foundation/FileManager/trashItem(at:resultingItemURL:))

Moves an item to the trash.

### Replacing items

[`replaceItemAt(_:withItemAt:backupItemName:options:)`](/documentation/Foundation/FileManager/replaceItemAt(_:withItemAt:backupItemName:options:))

Replaces the contents of the item at the specified URL in a manner that ensures no data loss occurs.

[`replaceItem(at:withItemAt:backupItemName:options:resultingItemURL:)`](/documentation/Foundation/FileManager/replaceItem(at:withItemAt:backupItemName:options:resultingItemURL:))

Replaces the contents of the item at the specified URL in a manner that ensures no data loss occurs.

[`FileManager.ItemReplacementOptions`](/documentation/Foundation/FileManager/ItemReplacementOptions)

Options for specifying the behavior of file replacement operations.

### Moving and copying items

[`copyItem(at:to:)`](/documentation/Foundation/FileManager/copyItem(at:to:))

Copies the file at the specified URL to a new location synchronously.

[`copyItem(atPath:toPath:)`](/documentation/Foundation/FileManager/copyItem(atPath:toPath:))

Copies the item at the specified path to a new location synchronously.

[`moveItem(at:to:)`](/documentation/Foundation/FileManager/moveItem(at:to:))

Moves the file or directory at the specified URL to a new location synchronously.

[`moveItem(atPath:toPath:)`](/documentation/Foundation/FileManager/moveItem(atPath:toPath:))

Moves the file or directory at the specified path to a new location synchronously.

### Managing iCloud-based items

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

An opaque token that represents the current user’s iCloud Drive Documents identity.

[`url(forUbiquityContainerIdentifier:)`](/documentation/Foundation/FileManager/url(forUbiquityContainerIdentifier:))

Returns the URL for the iCloud container associated with the specified identifier and establishes access to that container.

[`isUbiquitousItem(at:)`](/documentation/Foundation/FileManager/isUbiquitousItem(at:))

Returns a Boolean indicating whether the item is targeted for storage in iCloud.

[`setUbiquitous(_:itemAt:destinationURL:)`](/documentation/Foundation/FileManager/setUbiquitous(_:itemAt:destinationURL:))

Indicates whether the item at the specified URL should be stored in iCloud.

[`startDownloadingUbiquitousItem(at:)`](/documentation/Foundation/FileManager/startDownloadingUbiquitousItem(at:))

Starts downloading (if necessary) the specified item to the local system.

[`evictUbiquitousItem(at:)`](/documentation/Foundation/FileManager/evictUbiquitousItem(at:))

Removes the local copy of the specified item that’s stored in iCloud.

[`url(forPublishingUbiquitousItemAt:expiration:)`](/documentation/Foundation/FileManager/url(forPublishingUbiquitousItemAt:expiration:))

Returns a URL that can be emailed to users to allow them to download a copy of a flat file item from iCloud.

### Accessing file provider services

[`getFileProviderServicesForItem(at:completionHandler:)`](/documentation/Foundation/FileManager/getFileProviderServicesForItem(at:completionHandler:))

Returns the services provided by the File Provider extension that manages the item at the given URL.

[`NSFileProviderService`](/documentation/Foundation/NSFileProviderService)

A service that provides a custom communication channel between your app and a File Provider extension.

[`NSFileProviderServiceName`](/documentation/Foundation/NSFileProviderServiceName)

The name used to identify a File Provider service.

### Controlling file provider synchronization

[`NSFileManagerSupportedSyncControls`](/documentation/Foundation/NSFileManagerSupportedSyncControls)

An option set of the sync controls available for an item.

[`pauseSyncForUbiquitousItem(at:completionHandler:)`](/documentation/Foundation/FileManager/pauseSyncForUbiquitousItem(at:completionHandler:))

Asynchronously pauses sync of an item at the given URL.

[`resumeSyncForUbiquitousItem(at:with:completionHandler:)`](/documentation/Foundation/FileManager/resumeSyncForUbiquitousItem(at:with:completionHandler:))

Asynchronously resumes the sync on a paused item using the given resume behavior.

[`NSFileManagerResumeSyncBehavior`](/documentation/Foundation/NSFileManagerResumeSyncBehavior)

The behaviors the file manager can apply to resolve conflicts when resuming a sync.

[`fetchLatestRemoteVersionOfItem(at:completionHandler:)`](/documentation/Foundation/FileManager/fetchLatestRemoteVersionOfItem(at:completionHandler:))

Asynchronously fetches the latest remote version of a given item from the server.

[`NSFileVersion`](/documentation/Foundation/NSFileVersion)

A snapshot of a file at a specific point in time.

[`uploadLocalVersionOfUbiquitousItem(at:withConflictResolutionPolicy:completionHandler:)`](/documentation/Foundation/FileManager/uploadLocalVersionOfUbiquitousItem(at:withConflictResolutionPolicy:completionHandler:))

Asynchronously uploads the local version of the item using the provided conflict resolution policy.

[`NSFileManagerUploadLocalVersionConflictPolicy`](/documentation/Foundation/NSFileManagerUploadLocalVersionConflictPolicy)

The policies the file manager can apply to resolve conflicts when uploading a local version of a file.

### Creating symbolic and hard links

[`createSymbolicLink(at:withDestinationURL:)`](/documentation/Foundation/FileManager/createSymbolicLink(at:withDestinationURL:))

Creates a symbolic link at the specified URL that points to an item at the given URL.

[`createSymbolicLink(atPath:withDestinationPath:)`](/documentation/Foundation/FileManager/createSymbolicLink(atPath:withDestinationPath:))

Creates a symbolic link that points to the specified destination.

[`linkItem(at:to:)`](/documentation/Foundation/FileManager/linkItem(at:to:))

Creates a hard link between the items at the specified URLs.

[`linkItem(atPath:toPath:)`](/documentation/Foundation/FileManager/linkItem(atPath:toPath:))

Creates a hard link between the items at the specified paths.

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

Returns the path of the item pointed to by a symbolic link.

### Determining access to files

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

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

[`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.

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

Returns a Boolean value that indicates whether the invoking object appears able to read a specified file.

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

Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.

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

Returns a Boolean value that indicates whether the operating system appears able to execute a specified file.

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

Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file.

### Getting and setting attributes

[`componentsToDisplay(forPath:)`](/documentation/Foundation/FileManager/componentsToDisplay(forPath:))

Returns an array of strings representing the user-visible components of a given path.

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

Returns the display name of the file or directory at a specified path.

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

Returns the attributes of the item at a given path.

[`attributesOfFileSystem(forPath:)`](/documentation/Foundation/FileManager/attributesOfFileSystem(forPath:))

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

[`setAttributes(_:ofItemAtPath:)`](/documentation/Foundation/FileManager/setAttributes(_:ofItemAtPath:))

Sets the attributes of the specified file or directory.

### Getting and comparing file contents

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

Returns the contents of the file at the specified path.

[`contentsEqual(atPath:andPath:)`](/documentation/Foundation/FileManager/contentsEqual(atPath:andPath:))

Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.

### Getting the relationship between items

[`getRelationship(_:ofDirectoryAt:toItemAt:)`](/documentation/Foundation/FileManager/getRelationship(_:ofDirectoryAt:toItemAt:))

Determines the type of relationship that exists between a directory and an item.

[`getRelationship(_:of:in:toItemAt:)`](/documentation/Foundation/FileManager/getRelationship(_:of:in:toItemAt:))

Determines the type of relationship that exists between a system directory and the specified item.

[`FileManager.URLRelationship`](/documentation/Foundation/FileManager/URLRelationship)

Constants indicating the relationship between a directory and an item.

### Converting file paths to strings

[`fileSystemRepresentation(withPath:)`](/documentation/Foundation/FileManager/fileSystemRepresentation(withPath:))

Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system.

[`string(withFileSystemRepresentation:length:)`](/documentation/Foundation/FileManager/string(withFileSystemRepresentation:length:))

Returns an [`NSString`](/documentation/Foundation/NSString) object whose contents are derived from the specified C-string path.

### Managing the delegate

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

The delegate of the file manager object.

### Managing the current directory

[`changeCurrentDirectoryPath(_:)`](/documentation/Foundation/FileManager/changeCurrentDirectoryPath(_:))

Changes the path of the current working directory to the specified path.

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

The path to the program’s current directory.

### Unmounting volumes

[`unmountVolume(at:options:completionHandler:)`](/documentation/Foundation/FileManager/unmountVolume(at:options:completionHandler:))

Starts the process of unmounting the specified volume.

[`FileManager.UnmountOptions`](/documentation/Foundation/FileManager/UnmountOptions)

Options that specify the behavior of an unmount operation.

[`NSFileManagerUnmountDissentingProcessIdentifierErrorKey`](/documentation/Foundation/NSFileManagerUnmountDissentingProcessIdentifierErrorKey)

The process identifier of the process that prevented a volume from unmounting.

### Working with HFS file types

[`NSFileTypeForHFSTypeCode(_:)`](/documentation/Foundation/NSFileTypeForHFSTypeCode(_:))

Returns a string encoding a file type code.

[`NSHFSTypeCodeFromFileType(_:)`](/documentation/Foundation/NSHFSTypeCodeFromFileType(_:))

Returns a file type code.

[`NSHFSTypeOfFile(_:)`](/documentation/Foundation/NSHFSTypeOfFile(_:))

Returns a string encoding a file type.

### Determining resource fork support

[`NSFoundationVersionWithFileManagerResourceForkSupport`](/documentation/Foundation/NSFoundationVersionWithFileManagerResourceForkSupport)

The version of the Foundation framework in which `NSFileManager` first supported resource forks.

### Working with notifications

[`NSUbiquityIdentityDidChange`](/documentation/Foundation/NSNotification/Name-swift.struct/NSUbiquityIdentityDidChange)

Sent after the iCloud (“ubiquity”) identity has changed.

### Working with notification messages

[`FileManager.UbiquityIdentityDidChangeMessage`](/documentation/Foundation/FileManager/UbiquityIdentityDidChangeMessage)

A message a file manager sends after the iCloud (“ubiquity”) identity changes.

### Supporting Types

[`FileManager.DirectoryEnumerationOptions`](/documentation/Foundation/FileManager/DirectoryEnumerationOptions)

Options for enumerating the contents of directories.

[`FileManager.SearchPathDirectory`](/documentation/Foundation/FileManager/SearchPathDirectory)

The location of significant directories.

[`FileManager.SearchPathDomainMask`](/documentation/Foundation/FileManager/SearchPathDomainMask)

Domain constants specifying base locations to use when you search for significant directories.

[`FileAttributeKey`](/documentation/Foundation/FileAttributeKey)

Keys in dictionaries used to get and set file attributes.

[`FileAttributeType`](/documentation/Foundation/FileAttributeType)

Values representing a file’s type attribute.

[`FileProtectionType`](/documentation/Foundation/FileProtectionType)

Protection level values that can be associated with a file attribute key.

[`URLFileProtection`](/documentation/Foundation/URLFileProtection)

Protection-level values for a URL resource key.

### Deprecated Methods

[`copyPath:toPath:handler:`](/documentation/Foundation/NSFileManager/copyPath:toPath:handler:)

Copies the directory or file specified in a given path to a different location in the file system identified by another path.

[`movePath:toPath:handler:`](/documentation/Foundation/NSFileManager/movePath:toPath:handler:)

Moves the directory or file specified by a given path to a different location in the file system identified by another path.

[`removeFileAtPath:handler:`](/documentation/Foundation/NSFileManager/removeFileAtPath:handler:)

Deletes the file, link, or directory (including, recursively, all subdirectories, files, and links in the directory) identified by a given path.

[`changeFileAttributes(_:atPath:)`](/documentation/Foundation/FileManager/changeFileAttributes(_:atPath:))

Changes the attributes of a given file or directory.

[`fileAttributes(atPath:traverseLink:)`](/documentation/Foundation/FileManager/fileAttributes(atPath:traverseLink:))

Returns a dictionary that describes the POSIX attributes of the file specified at a given.

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

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

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

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

[`createDirectory(atPath:attributes:)`](/documentation/Foundation/FileManager/createDirectory(atPath:attributes:))

Creates a directory (without contents) at a given path with given attributes.

[`createSymbolicLink(atPath:pathContent:)`](/documentation/Foundation/FileManager/createSymbolicLink(atPath:pathContent:))

Creates a symbolic link identified by a given path that refers to a given location.

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

Returns the path of the directory or file that a symbolic link at a given path refers to.

[`linkPath:toPath:handler:`](/documentation/Foundation/NSFileManager/linkPath:toPath:handler:)

Creates a link from a source to a destination.

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:shouldProceedAfterError:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:willProcessPath:)>

[`replaceItemAtURL(originalItemURL:withItemAtURL:backupItemName:options:)`](/documentation/Foundation/FileManager/replaceItemAtURL(originalItemURL:withItemAtURL:backupItemName:options:))

Replaces the contents of the item at the specified URL in a manner that ensures no data loss occurs.



---

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)