Configure advanced copy behavior with Options
mainFor fine-grained control over the copy process, use cp.Copy(src, dest, opt) where opt is an instance of Options.
Common use cases for Options include:
- Skipping files: Use the
Skipfunction to filter files based onos.FileInfoor path strings. - Handling existing directories: Use
OnDirExiststo define an action when the destination directory already exists. - Symlink behavior: Use
OnSymlinkto decide how to handle symbolic links. - Error handling: Use
OnErrorto intercept and decide how to handle specific errors during the copy process. - Permissions: Use
PermissionControlto either preserve, add, or ignore permissions (e.g.,AddPermission(0222)orDoNothing). - Performance and Concurrency: Adjust
NumOfWorkersto control concurrent copying orCopyBufferSizeto change the buffer size (defaults to 32KB).
opt := Options{
Skip: func(info os.FileInfo, src, dest string) (bool, error) {
return strings.HasSuffix(src, ".git"), nil
},
}
err := Copy("your/directory", "your/directory.copy", opt)