---
title: "createItem(named:type:inDirectory:attributes:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/operations/createitem(named:type:indirectory:attributes:replyhandler:)"
---

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

Creates a new file or directory item.

## Declaration

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

```swift
func createItem(named name: FSFileName, type: FSItem.ItemType, inDirectory directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest) async throws -> (FSItem, FSFileName)
```

## Parameters

- `name`: The new item’s name.
- `type`: The new item’s type. Valid values are doc://FSKit/documentation/FSKit/FSItem/ItemType/file or doc://FSKit/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 doc://FSKit/documentation/FSKit/FSItem and its doc://FSKit/documentation/FSKit/FSFileName, along with a nil error. If creation fails, pass the relevant error as the third parameter; FSKit ignores any doc://FSKit/documentation/FSKit/FSItem or doc://FSKit/documentation/FSKit/FSFileName in this case. For an async Swift implementation, there’s no reply handler; simply return a tuple of the doc://FSKit/documentation/FSKit/FSItem and its doc://FSKit/documentation/FSKit/FSFileName or throw an error.

## Discussion

Discussion If an item named name already exists in the directory indicated by directory, complete the request with an error with a domain of NSPOSIXErrorDomain and a code of EEXIST.
