<!--
{
  "availability" : [
    "macOS: 15.4.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolume/Operations/createLink(to:named:inDirectory:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeOperations(im)createLinkToItem:named:inDirectory:replyHandler:"
  },
  "title" : "createLink(to:named:inDirectory:replyHandler:)"
}
-->

# createLink(to:named:inDirectory:replyHandler:)

Creates a new hard link.

```
func createLink(to item: FSItem, named name: FSFileName, inDirectory directory: FSItem, replyHandler reply: @escaping @Sendable (FSFileName?, (any Error)?) -> Void)
```

## Parameters

`item`

The existing item to which to link.

`name`

The name for the new link.

`directory`

The directory in which to create the link.

`reply`

A block or closure to indicate success or failure. If creation succeeds, pass an [`FSFileName`](/documentation/FSKit/FSFileName) of the newly-created link and a `nil` error. If creation fails, pass the relevant error as the second parameter; FSKit ignores any [`FSFileName`](/documentation/FSKit/FSFileName) in this case. For an `async` Swift implementation, there’s no reply handler; simply return the [`FSFileName`](/documentation/FSKit/FSFileName) or throw an error.

## Discussion

If creating the link fails, complete the request with an error with a domain of <doc://com.apple.documentation/documentation/Foundation/NSPOSIXErrorDomain> and the following error codes:

- `EEXIST` if there’s already an item named `name` in the directory.
- `EMLINK` if creating the link would exceed the maximum number of hard links supported on `item`.
- `ENOTSUP` if the file system doesn’t support creating hard links to the type of file system object that `item` represents.

---

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)