<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileWrapper",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileWrapper"
  },
  "title" : "FileWrapper"
}
-->

# FileWrapper

A representation of a node (a file, directory, or symbolic link) in the file system.

```
class FileWrapper
```

## Overview

The [`FileWrapper`](/documentation/Foundation/FileWrapper) class provides access to the attributes and contents of file system nodes. A file system node is a file, directory, or symbolic link. Instances of this class are known as file wrappers.

> Note:
> Starting in macOS 10.7, ``doc://com.apple.foundation/documentation/Foundation/FileWrapper`` moved from Application Kit to Foundation. As a result of this the `icon`, and `setIcon:` methods have moved to a new category of ``doc://com.apple.foundation/documentation/Foundation/FileWrapper`` that remains in Application Kit.

File wrappers represent a file system node as an object that can be displayed as an image (and possibly edited in place), saved to the file system, or transmitted to another application.

There are three types of file wrappers:

- Regular-file file wrapper: Represents a regular file.
- Directory file wrapper: Represents a directory.
- Symbolic-link file wrapper: Represents a symbolic link.

A file wrapper has these attributes:

- Filename. Name of the file system node the file wrapper represents.
- file-system attributes. See [`FileManager`](/documentation/Foundation/FileManager) for information on the contents of the `attributes` dictionary.
- Regular-file contents. Applicable only to regular-file file wrappers.
- File wrappers. Applicable only to directory file wrappers.
- Destination node. Applicable only to symbolic-link file wrappers.

## Topics

### Creating File Wrappers

This class has several designated initializers.

[`init(url:options:)`](/documentation/Foundation/FileWrapper/init(url:options:)-70161)

Initializes a file wrapper instance whose kind is determined by the type of file-system node located by the URL.

[`init(path:)`](/documentation/Foundation/FileWrapper/init(path:))

Initializes a file wrapper instance whose kind is determined by the type of file-system node located by the path.

[`init(directoryWithFileWrappers:)`](/documentation/Foundation/FileWrapper/init(directoryWithFileWrappers:))

Initializes the receiver as a directory file wrapper, with a given file-wrapper list.

[`init(regularFileWithContents:)`](/documentation/Foundation/FileWrapper/init(regularFileWithContents:))

Initializes the receiver as a regular-file file wrapper.

[`init(symbolicLinkWithDestination:)`](/documentation/Foundation/FileWrapper/init(symbolicLinkWithDestination:))

Initializes the receiver as a symbolic-link file wrapper.

[`init(symbolicLinkWithDestinationURL:)`](/documentation/Foundation/FileWrapper/init(symbolicLinkWithDestinationURL:))

Initializes the receiver as a symbolic-link file wrapper that links to a specified file.

[`init(serializedRepresentation:)`](/documentation/Foundation/FileWrapper/init(serializedRepresentation:))

Initializes the receiver as a regular-file file wrapper from given serialized data.

### Querying File Wrappers

[`isRegularFile`](/documentation/Foundation/FileWrapper/isRegularFile)

This property contains a boolean value that indicates whether the file wrapper object is a regular-file.

[`isDirectory`](/documentation/Foundation/FileWrapper/isDirectory)

This property contains a boolean value indicating whether the file wrapper is a directory file wrapper.

[`isSymbolicLink`](/documentation/Foundation/FileWrapper/isSymbolicLink)

A boolean that indicates whether the file wrapper object is a symbolic-link file wrapper.

### Accessing File-Wrapper Information

[`fileWrappers`](/documentation/Foundation/FileWrapper/fileWrappers)

The file wrappers contained by a directory file wrapper.

[`addFileWrapper(_:)`](/documentation/Foundation/FileWrapper/addFileWrapper(_:))

Adds a child file wrapper to the receiver, which must be a directory file wrapper.

[`removeFileWrapper(_:)`](/documentation/Foundation/FileWrapper/removeFileWrapper(_:))

Removes a child file wrapper from the receiver, which must be a directory file wrapper.

[`addFile(withPath:)`](/documentation/Foundation/FileWrapper/addFile(withPath:))

Creates a file wrapper from a given file-system node and adds it to the receiver, which must be a directory file wrapper.

[`addRegularFile(withContents:preferredFilename:)`](/documentation/Foundation/FileWrapper/addRegularFile(withContents:preferredFilename:))

Creates a regular-file file wrapper with the given contents and adds it to the receiver, which must be a directory file wrapper.

[`addSymbolicLink(withDestination:preferredFilename:)`](/documentation/Foundation/FileWrapper/addSymbolicLink(withDestination:preferredFilename:))

Creates a symbolic-link file wrapper pointing to a given file-system node and adds it to the receiver, which must be a directory file wrapper.

[`keyForChildFileWrapper(_:)`](/documentation/Foundation/FileWrapper/keyForChildFileWrapper(_:))

Returns the dictionary key used by a directory to identify a given file wrapper.

[`symbolicLinkDestination()`](/documentation/Foundation/FileWrapper/symbolicLinkDestination())

Provides the pathname referenced by the file wrapper object, which must be a symbolic-link file wrapper.

[`symbolicLinkDestinationURL`](/documentation/Foundation/FileWrapper/symbolicLinkDestinationURL)

The URL referenced by the file wrapper object, which must be a symbolic-link file wrapper.

### Updating File Wrappers

[`needsToBeUpdated(fromPath:)`](/documentation/Foundation/FileWrapper/needsToBeUpdated(fromPath:))

Indicates whether the file wrapper needs to be updated to match a given file-system node.

[`matchesContents(of:)`](/documentation/Foundation/FileWrapper/matchesContents(of:))

Indicates whether the contents of a file wrapper matches a directory, regular file, or symbolic link on disk.

[`update(fromPath:)`](/documentation/Foundation/FileWrapper/update(fromPath:))

Updates the file wrapper to match a given file-system node.

[`read(from:options:)`](/documentation/Foundation/FileWrapper/read(from:options:))

Recursively rereads the entire contents of a file wrapper from the specified location on disk.

### Serializing

[`serializedRepresentation`](/documentation/Foundation/FileWrapper/serializedRepresentation)

The contents of the file wrapper as an opaque data object.

### Accessing Files

[`filename`](/documentation/Foundation/FileWrapper/filename)

The filename of the file wrapper object

[`preferredFilename`](/documentation/Foundation/FileWrapper/preferredFilename)

The preferred filename for the file wrapper object.

[`fileAttributes`](/documentation/Foundation/FileWrapper/fileAttributes)

A dictionary of file attributes.

[`regularFileContents`](/documentation/Foundation/FileWrapper/regularFileContents)

The contents of the file-system node associated with a regular-file file wrapper.

### Writing Files

[`write(toFile:atomically:updateFilenames:)`](/documentation/Foundation/FileWrapper/write(toFile:atomically:updateFilenames:))

Writes a file wrapper’s contents to a given file-system node.

[`write(to:options:originalContentsURL:)`](/documentation/Foundation/FileWrapper/write(to:options:originalContentsURL:))

Recursively writes the entire contents of a file wrapper to a given file-system URL.

### Working with Icons

[`icon`](/documentation/Foundation/FileWrapper/icon)

The icon that represents the file wrapper.

### Constants

[`FileWrapper.ReadingOptions`](/documentation/Foundation/FileWrapper/ReadingOptions)

Reading options that can be set by the [`init(url:options:)`](/documentation/Foundation/FileWrapper/init(url:options:)-70161) and [`read(from:options:)`](/documentation/Foundation/FileWrapper/read(from:options:)) methods.

[`FileWrapper.WritingOptions`](/documentation/Foundation/FileWrapper/WritingOptions)

Writing options that can be set by the [`write(to:options:originalContentsURL:)`](/documentation/Foundation/FileWrapper/write(to:options:originalContentsURL:)) method.



---

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)