Learn R Programming

fritools (version 3.3.0)

file_save: Create a Copy of a File

Description

I often want a timestamped copy as backup of a file or directory.

Usage

file_save(
  x,
  file_extension_pattern = "\\.[A-z]{1,5}$",
  force = TRUE,
  recursive = dir.exists(x),
  stop_on_error = TRUE
)

Arguments

x

A path to a file.

file_extension_pattern

A Pattern to mark a file extension. If matched, the time stamp will get inserted before that pattern.

force

Force even if file_extension_pattern is not matched. Set to FALSE to skip stamping such files.

recursive

Passed to file.copy.

stop_on_error

Throw an exception on error?

Value

TRUE on success, FALSE otherwise.

See Also

Other operating system functions: file_copy(), get_boolean_envvar(), get_run_r_tests(), is_installed(), is_r_package_installed(), is_success(), is_windows(), view(), vim(), with_dir()

Other file utilities: file_copy(), file_modified_last(), find_files(), get_mtime(), get_unique_string(), is_files_current(), is_path(), paths, search_files(), split_code_file(), touch()

Examples

Run this code
# NOT RUN {
f <- tempfile()
try(file_save(f))
touch(f)
file_save(f, recursive = FALSE)
f <- paste0(file.path(tempfile()), ".txt")
touch(f)
file_save(f) # file.copy gives a warning
dir(tempdir())
# }

Run the code above in your browser using DataLab