<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.5.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSFileManager/copyPath:toPath:handler:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)copyPath:toPath:handler:"
  },
  "title" : "copyPath:toPath:handler:"
}
-->

# copyPath:toPath:handler:

Copies the directory or file specified in a given path to a different location in the file system identified by another path.

```
- (BOOL) copyPath:(NSString *) src toPath:(NSString *) dest handler:(id) handler;
```

## Parameters

`src`

The location of the source file.

`dest`

The location to which to copy the file specified by `source`.

`handler`

An object that responds to the callback messages <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:willProcessPath:)> and <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:shouldProceedAfterError:)>. You can specify `nil` for `handler`; if you do so and an error occurs, the method automatically returns <doc://com.apple.documentation/documentation/Swift/false>.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the copy operation is successful. If the operation is not successful, but the callback handler of <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:shouldProceedAfterError:)> returns <doc://com.apple.documentation/documentation/Swift/true>, [`copyPath:toPath:handler:`](/documentation/Foundation/NSFileManager/copyPath:toPath:handler:) also returns <doc://com.apple.documentation/documentation/Swift/true>. Otherwise this method returns <doc://com.apple.documentation/documentation/Swift/false>. The method also attempts to make the attributes of the directory or file at `destination` identical to `source`, but ignores any failure at this attempt.

## Discussion

If `source` is a file, the method creates a file at `destination` that holds the exact contents of the original file (this includes BSD special files). If `source` is a directory, the method creates a new directory at `destination` and recursively populates it with duplicates of the files and directories contained in `source`, preserving all links. The file specified in `source` must exist, while `destination` must not exist prior to the operation. When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename. Symbolic links are not traversed but are themselves copied. File or directory attributes—that is, metadata such as owner and group numbers, file permissions, and modification date—are also copied.

The handler callback mechanism is similar to delegation. `NSFileManager` sends <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:willProcessPath:)> when it begins a copy, move, remove, or link operation. It sends <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/fileManager(_:shouldProceedAfterError:)> when it encounters any error in processing.

### Special Considerations

Because this method does not return error information, it has been deprecated as of OS X v10.5. Use [`copyItem(at:to:)`](/documentation/Foundation/FileManager/copyItem(at:to:)) instead.

## See Also

[`func linkItem(at: URL, to: URL) throws`](/documentation/Foundation/FileManager/linkItem(at:to:))

Creates a hard link between the items at the specified URLs.

[`func copyItem(atPath: String, toPath: String) throws`](/documentation/Foundation/FileManager/copyItem(atPath:toPath:))

Copies the item at the specified path to a new location synchronously.

[`func removeItem(atPath: String) throws`](/documentation/Foundation/FileManager/removeItem(atPath:))

Removes the file or directory at the specified path.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)