<!--
{
  "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/filename",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileWrapper(py)filename"
  },
  "title" : "filename"
}
-->

# filename

The filename of the file wrapper object

```
var filename: String? { get set }
```

## Discussion

This property contains the file wrapper’s filename, or `nil` when the file wrapper has no corresponding file-system node.

The filename is used for record-keeping purposes only and is set automatically when the file wrapper is created from the file system using [`init(url:options:)`](/documentation/Foundation/FileWrapper/init(url:options:)-70161) and when it’s saved to the file system using [`write(to:options:originalContentsURL:)`](/documentation/Foundation/FileWrapper/write(to:options:originalContentsURL:)) (although this method allows you to request that the filename not be updated).

The filename is usually the same as the preferred filename, but might instead be a name derived from the preferred filename.  You can use this method to get the name of a child that’s just been read. Don’t use this method to get the name of a child that’s about to be written, because the name might be about to change; send [`keyForChildFileWrapper(_:)`](/documentation/Foundation/FileWrapper/keyForChildFileWrapper(_:)) to the parent instead.

---

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)