replaceItem(at:withItemAt:)

Replaces the item at destinationPath with the item at existingPath.

FileSystem.swift:542
iOS
13.0+
macOS
10.15+
tvOS
13.0+
watchOS
6.0+
func replaceItem(at destinationPath: FilePath, withItemAt existingPath: FilePath) async throws

Parameters

destinationPath

The path of the file or directory to replace.

existingPath

The path of the existing file or directory.

Only regular files, symbolic links and directories may replace the item at the existing path. The file at the destination path isn’t required to exist. If it does exist it does not have to match the type of the file it is being replaced with.

Errors

Error codes thrown include:

  • notFound if the item at existingPath does not exist.

Implementation details

Uses the rename(2) system call.