Description Usage Arguments Value Examples
This function is a wrapper around fs::file_copy()
, with the modification that,
if a file exists at the new_path
the user will be prompted to overwrite it.
1 | file_copy(path, new_path)
|
path |
A character string of the file path to be copied. |
new_path |
A character string of the path where the file should be copied to. |
The new path (invisibly) if the file is copied. Nothing otherwise.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | if (interactive()) {
# Create a test file
jdtools::file_new_text("test-file_copy", open = FALSE)
# Copy the file with no problem
jdtools::file_copy(path = "test-file_copy.txt",
new_path = "test-file_copy-2.txt")
# Upon repeating, this will prompt the user whether or nott
# test-file_copy-2.txt should be overwritten.
jdtools::file_copy(path = "test-file_copy.txt",
new_path = "test-file_copy-2.txt")
# A copied file can be piped into `jdtools::file_open()`
jdtools::file_copy(path = "test-file_copy.txt",
new_path = "test-file_copy-3.txt") %>%
jdtools::file_open()
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.