robocopy
on Windows and rsync
on Linux/macOSR/cache-helpers.R
copyFile.Rd
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.
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.
copySingleFile( from = NULL, to = NULL, useRobocopy = TRUE, overwrite = TRUE, delDestination = FALSE, create = TRUE, silent = FALSE ) copyFile( from = NULL, to = NULL, useRobocopy = TRUE, overwrite = TRUE, delDestination = FALSE, create = TRUE, silent = FALSE )
from | The source file. |
---|---|
to | The new file. |
useRobocopy | For Windows, this will use a system call to |
overwrite | Passed to |
delDestination | Logical, whether the destination should have any files deleted,
if they don't exist in the source. This is |
create | Passed to |
silent | Should a progress be printed. |
tmpDirFrom <- file.path(tempdir(), "example_fileCopy_from") tmpDirTo <- file.path(tempdir(), "example_fileCopy_to") tmpFile1 <- tempfile("file1", tmpDirFrom, ".csv") tmpFile2 <- tempfile("file2", tmpDirFrom, ".csv") checkPath(tmpDirFrom, create = TRUE)#> [1] "C:/Users/EMCINT~1.L-V/AppData/Local/Temp/RtmpamdaBp/example_fileCopy_from"f1 <- normalizePath(tmpFile1, mustWork = FALSE) f2 <- normalizePath(tmpFile2, mustWork = FALSE) t1 <- normalizePath(file.path(tmpDirTo, basename(tmpFile1)), mustWork = FALSE) t2 <- normalizePath(file.path(tmpDirTo, basename(tmpFile2)), mustWork = FALSE) write.csv(data.frame(a = 1:10, b = runif(10), c = letters[1:10]), f1) write.csv(data.frame(c = 11:20, d = runif(10), e = letters[11:20]), f2) copyFile(c(f1, f2), c(t1, t2))#> C:\\Users\\EMCINT~1.L-V\\AppData\\Local\\Temp\\RtmpamdaBp\\example_fileCopy_from\\file1a045ad32fbe.csv #> "C:\\Users\\EMCINT~1.L-V\\AppData\\Local\\Temp\\RtmpamdaBp\\example_fileCopy_to\\file1a045ad32fbe.csv" #> C:\\Users\\EMCINT~1.L-V\\AppData\\Local\\Temp\\RtmpamdaBp\\example_fileCopy_from\\file2a04620860c5.csv #> "C:\\Users\\EMCINT~1.L-V\\AppData\\Local\\Temp\\RtmpamdaBp\\example_fileCopy_to\\file2a04620860c5.csv"#> [1] TRUE#> [1] TRUE#> [1] FALSE#> [1] TRUE#> [1] TRUE