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

# createItem(named:type:inDirectory:attributes:replyHandler:)

Creates a new file or directory item.

```
func createItem(named name: FSFileName, type: FSItem.ItemType, inDirectory directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, replyHandler reply: @escaping @Sendable (FSItem?, FSFileName?, (any Error)?) -> Void)
```

## Parameters

`name`

The new item’s name.

`type`

The new item’s type.  Valid values are [`FSItem.ItemType.file`](/documentation/FSKit/FSItem/ItemType/file) or [`FSItem.ItemType.directory`](/documentation/FSKit/FSItem/ItemType/directory).

`directory`

The directory in which to create the item.

`newAttributes`

Attributes to apply to the new item.

`reply`

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

## Discussion

If an item named `name` already exists in the directory indicated by `directory`, complete the request with an error with a domain of <doc://com.apple.documentation/documentation/Foundation/NSPOSIXErrorDomain> and a code of `EEXIST`.

---

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)