Contents

createItem(named:type:in:attributes:context:replyHandler:)

Creates a new file or directory item.

Declaration

func createItem(named name: FSFileName, type: FSItem.ItemType, in directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, context: FSContext, replyHandler reply: @escaping  @Sendable (FSCreateItemResult?, (any Error)?) -> Void)
func createItem(named name: FSFileName, type: FSItem.ItemType, in directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, context: FSContext) async throws -> FSCreateItemResult

Parameters

  • name:

    The new item’s name.

  • type:

    The new item’s type. Valid values are File or Directory.

  • directory:

    The directory in which to create the item.

  • newAttributes:

    Attributes to apply to the new item.

  • context:

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

  • reply:

    A block or closure to indicate success or failure. If creation succeeds, pass an instance of Fscreateitemresult containing the newly-created Fsitem, its Fsfilename, its Attributes, the updated Attributes of the parent directory, and the volume’s updated free space, along with a nil error. If creation fails, pass the relevant error as the second parameter; FSKit ignores the Fscreateitemresult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance 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 NSPOSIXErrorDomain and a code of EEXIST.

See Also

Working with items