<!--
{
  "availability" : [
    "macOS: 27.3.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolume/Handler/renameItem(_:inDirectory:named:to:inDirectory:overItem:flags:context:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeHandler(im)renameItem:inDirectory:named:toNewName:inDirectory:overItem:flags:context:replyHandler:"
  },
  "title" : "renameItem(_:inDirectory:named:to:inDirectory:overItem:flags:context:replyHandler:)"
}
-->

# renameItem(_:inDirectory:named:to:inDirectory:overItem:flags:context:replyHandler:)

Renames an item, honoring the flags of `renamex_np(2)`.

```
optional func renameItem(_ item: FSItem, inDirectory sourceDirectory: FSItem, named sourceName: FSFileName, to destinationName: FSFileName, inDirectory destinationDirectory: FSItem, overItem: FSItem?, flags: FSVolume.RenameFlags, context: FSContext, replyHandler reply: @escaping @Sendable (FSRenameItemResult?, (any Error)?) -> Void)
```

```
optional func renameItem(_ item: FSItem, inDirectory sourceDirectory: FSItem, named sourceName: FSFileName, to destinationName: FSFileName, inDirectory destinationDirectory: FSItem, overItem: FSItem?, flags: FSVolume.RenameFlags, context: FSContext) async throws -> FSRenameItemResult
```

## Parameters

`item`

The file system object being renamed.

`sourceDirectory`

The directory that currently contains the item to rename.

`sourceName`

The name of the item within the source directory.

`destinationName`

The new name of the item as it appears in `destinationDirectory`.

`destinationDirectory`

The directory to contain the renamed object, which may be the same as `sourceDirectory`.

`overItem`

The file system object if the destination exists, as discovered in a prior lookup.

`flags`

The [`FSVolume.RenameFlags`](/documentation/FSKit/FSVolume/RenameFlags) requested by the caller. FSKit only passes flags included in [`supportedRenameFlags`](/documentation/FSKit/FSVolume/Handler/supportedRenameFlags). Honor them atomically as part of the rename.

`context`

An object that enables context-aware file system decisions throughout the operation.

`reply`

A block or closure to indicate success or failure. On success, pass an instance of [`FSRenameItemResult`](/documentation/FSKit/FSRenameItemResult) and a `nil` error; on failure, pass the relevant error. For an `async` Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

## Discussion

This method behaves like [`renameItem(_:inDirectory:named:to:inDirectory:overItem:context:replyHandler:)`](/documentation/FSKit/FSVolume/Handler/renameItem(_:inDirectory:named:to:inDirectory:overItem:context:replyHandler:)), but additionally receives the [`FSVolume.RenameFlags`](/documentation/FSKit/FSVolume/RenameFlags) requested by the caller. Implement this method when your file system can honor `renamex_np(2)` flags such as `FSRenameFlags/swap` and `FSRenameFlags/exclusive`.

Declare the flags your file system can honor with [`supportedRenameFlags`](/documentation/FSKit/FSVolume/Handler/supportedRenameFlags). FSKit advertises the matching `VOL_CAP_INT_RENAME_SWAP` and `VOL_CAP_INT_RENAME_EXCL` interface capabilities, and fails any rename requesting an undeclared flag with `ENOTSUP` before calling this method. If you don’t implement [`supportedRenameFlags`](/documentation/FSKit/FSVolume/Handler/supportedRenameFlags), FSKit assumes no flags are supported and this method only ever receives `FSRenameFlags/none`.

> Note: When a volume implements this method, FSKit dispatches **every** rename to it, including plain renames, for which `flags` is ``FSRenameFlags/none``, instead of ``doc://FSKit/documentation/FSKit/FSVolume/Handler/renameItem(_:inDirectory:named:to:inDirectory:overItem:context:replyHandler:)``.

---

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)