<!--
{
  "availability" : [
    "macOS: 15.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSFileName",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(cs)FSFileName"
  },
  "title" : "FSFileName"
}
-->

# FSFileName

The name of a file, expressed as a data buffer.

```
class FSFileName
```

## Overview

`FSFileName` is the class that carries filenames from the kernel to `FSModule` instances, and carries names back to the kernel as part of directory enumeration.

A filename is usually a valid UTF-8 sequence, but can be an arbitrary byte sequence that doesn’t conform to that format.
As a result, the [`data`](/documentation/FSKit/FSFileName/data) property always contains a value, but the [`string`](/documentation/FSKit/FSFileName/string) property may be empty.
An `FSModule` can receive an `FSFileName` that isn’t valid UTF-8 in two cases:

1. A program passes erroneous data to a system call. The `FSModule` treats this situation as an error.
2. An `FSModule` lacks the character encoding used for a file name.
   This situation occurs because some file system formats consider a filename to be an arbitrary “bag of bytes,” and leave character encoding up to the operating system.
   Without encoding information, the `FSModule` can only pass back the names it finds on disk.
   In this case, the behavior of upper layers such as <doc://com.apple.documentation/documentation/Foundation/FileManager> is unspecified.
   However, the `FSModule` must support looking up such names and using them as the source name of rename operations.
   The `FSModule` must also be able to support filenames that are derivatives of filenames returned from directory enumeration.
   Derivative filenames include Apple Double filenames (`"._Name"`), and editor backup filenames.

> Important: Don’t subclass this class.

## Topics

### Creating a filename

[`init(bytes:)`](/documentation/FSKit/FSFileName/init(bytes:))

[`initWithBytes:length:`](/documentation/FSKit/FSFileName/initWithBytes:length:)

Initializes a file name by copying a character sequence from a byte array.

[`nameWithBytes:length:`](/documentation/FSKit/FSFileName/nameWithBytes:length:)

Creates a filename by copying a character sequence from a byte array.

[`init(cString:)`](/documentation/FSKit/FSFileName/init(cString:))

[`initWithCString:`](/documentation/FSKit/FSFileName/initWithCString:)

Initializes a filename from a null-terminated character sequence.

[`nameWithCString:`](/documentation/FSKit/FSFileName/nameWithCString:)

Creates a filename from a null-terminated character sequence.

[`init(data:)`](/documentation/FSKit/FSFileName/init(data:))

Creates a filename by copying a character sequence data object.

[`nameWithData:`](/documentation/FSKit/FSFileName/nameWithData:)

Creates a filename by copying a character sequence data object.

[`init(string:)`](/documentation/FSKit/FSFileName/init(string:))

Creates a filename by copying a character sequence from a string instance.

[`nameWithString:`](/documentation/FSKit/FSFileName/nameWithString:)

Creates a filename by copying a character sequence from a string instance.

### Accessing filename properties

[`data`](/documentation/FSKit/FSFileName/data)

The byte sequence of the filename, as a data object.

[`string`](/documentation/FSKit/FSFileName/string)

The filename, represented as a Unicode string.

[`debugDescription`](/documentation/FSKit/FSFileName/debugDescription)

The filename, represented as a potentially lossy conversion to a string.



---

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)