Learn R Programming

reproducible (version 0.1.3)

copyFile: Copy a file using Robocopy on Windows and rsync on Linux/macOS

Description

This will copy an individual file faster using Robocopy on Windows, and using rsync on macOS and Linux.

Usage

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.

create

Passed to checkLazyDir.

silent

Should a progress be printed.

Examples

Run this code
# NOT RUN {
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
identical(read.csv(f1), read.csv(f2)) ## TRUE

unlink(tmpDirFrom, recursive = TRUE)
unlink(tmpDirTo, recursive = TRUE)

# }

Run the code above in your browser using DataLab