removeItem(at:)

Deletes the file or directory (and its contents) at path.

FileSystemProtocol.swift:606
iOS
13.0+
macOS
10.15+
tvOS
13.0+
watchOS
6.0+
@discardableResult func removeItem(at path: FilePath) async throws -> Int

Parameters

path

The path to delete.

Returns

The number of deleted items which may be zero if path did not exist.

The item to be removed must be a regular file, symbolic link or directory. If no file exists at the given path then this function returns zero.

If the item at the path is a directory then the contents of all of its subdirectories will be removed recursively before the directory at path. Symbolic links are removed (but their targets are not deleted).

The strategy for deletion will be determined automatically depending on the discovered platform.