file_copy: Copy Existing Files to a new Directory

Description Usage Arguments Value Examples

View source: R/func_files.R

Description

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.

Usage

1
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

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

}

jdtrat/jdtools documentation built on Dec. 20, 2021, 10:05 p.m.