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.

file_copy(path, new_path)

Arguments

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.

Value

The new path (invisibly) if the file is copied. Nothing otherwise.

Examples

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() }