Contents

FileManager

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

Declaration

class FileManager

Mentioned in

Overview

A file manager object lets you examine the contents of the file system and make changes to it. The 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 or NSString objects. The use of the 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 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 protocol.

In iOS 5.0 and later and in macOS 10.7 and later, 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 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 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 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

Accessing user directories

Locating system directories

Locating application group container directories

Discovering directory contents

Creating and deleting items

Replacing items

Moving and copying items

Managing iCloud-based items

Accessing file provider services

Controlling file provider synchronization

Creating symbolic and hard links

Determining access to files

Getting and setting attributes

Getting and comparing file contents

Getting the relationship between items

Converting file paths to strings

Managing the delegate

Managing the current directory

Unmounting volumes

Working with HFS file types

Determining resource fork support

Supporting Types

Notifications

Deprecated Methods

Structures

Instance Methods

See Also

File system operations