copyItem(at:to:shouldProceedAfterError:shouldCopyItem:)
Copies the item at the specified path to a new location.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
func copyItem(at sourcePath: FilePath, to destinationPath: FilePath, shouldProceedAfterError: @escaping (_ source: DirectoryEntry, _ error: Error) async throws -> Void, shouldCopyItem: @escaping (_ source: DirectoryEntry, _ destination: FilePath) async -> Bool) async throws
Parameters
- sourcePath
The path to the item to copy.
- destinationPath
The path at which to place the copy.
- shouldProceedAfterError
A closure which is executed to determine whether to continue copying files if an error is encountered during the operation. See Errors section for full details.
- shouldCopyItem
A closure which is executed before each copy to determine whether each item should be copied. See Filtering section for full details
The following error codes may be thrown:
notFound
if the item atsourcePath
does not exist,invalidArgument
if an item atdestinationPath
exists prior to the copy or its parent directory does not exist.
Note that other errors may also be thrown.
If sourcePath
is a symbolic link then only the link is copied. The copied file will preserve permissions and any extended attributes (if supported by the file system).
Parallelism
This overload uses platformDefault
which is likely to result in multiple concurrency domains being used in the event of copying a directory. See the detailed description on copyItem(at:to:strategy:shouldProceedAfterError:shouldCopyItem:)
for the implications of this with respect to the shouldProceedAfterError
and shouldCopyItem
callbacks