This is replacement for file.copy, but for one file at a time. The additional feature is that it will use Robocopy (on Windows) or rsync on Linux or Mac, if they exist. It will default back to file.copy if none of these exists. This will generally copy a large file faster using Robocopy on Windows, and using rsync on macOS and Linux. In particular, if there is a possibility that the file already exists, then this function should be very fast as it will do "update only", i.e., nothing.

copyFile(from = NULL, to = NULL, useRobocopy = TRUE, overwrite = TRUE,
  delDestination = FALSE, create = TRUE, silent = FALSE)

Arguments

from

The source file.

to

The new file.

useRobocopy

For Windows, this will use a system call to Robocopy which appears to be much faster than the internal file.copy function. Uses /MIR flag. Default TRUE.

overwrite

Passed to file.copy

delDestination

Logical, whether the destination should have any files deleted, if they don't exist in the source. This is /purge for RoboCopy and --delete for rsync.

create

Passed to checkPath.

silent

Should a progress be printed.

Examples

tmpDirFrom <- file.path(tempdir(), "example_fileCopy_from") tmpDirTo <- file.path(tempdir(), "example_fileCopy_to") tmpFile <- tempfile("file", tmpDirFrom, ".csv") dir.create(tmpDirFrom) f1 <- normalizePath(tmpFile, mustWork = FALSE) f2 <- normalizePath(file.path(tmpDirTo, basename(tmpFile)), mustWork = FALSE) write.csv(data.frame(a = 1:10, b = runif(10), c = letters[1:10]), f1) copyFile(f1, f2) file.exists(f2) ## TRUE
#> [1] TRUE
identical(read.csv(f1), read.csv(f2)) ## TRUE
#> [1] TRUE
unlink(tmpDirFrom, recursive = TRUE) unlink(tmpDirTo, recursive = TRUE)