file_save: Create a Copies of Files

View source: R/file_save.R

file_saveR Documentation

Create a Copies of Files

Description

I often want a timestamped copies as backup of files or directories.

Usage

file_save(
  ...,
  file_extension_pattern = "\\.[A-z]{1,5}$",
  force = TRUE,
  recursive = NA,
  stop_on_error = TRUE,
  overwrite = FALSE
)

Arguments

...

Paths to files.

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. Defaults to 'if the current path is a directory, then TRUE, else FALSE'.

stop_on_error

Throw an exception on error?

overwrite

Passed to file.copy.

Value

A vector of boolean values indicating success or failure.

See Also

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

Other file utilities: clipboard_path(), delete_trailing_blank_lines(), delete_trailing_whitespace(), develop_test(), file_copy(), file_modified_last(), find_files(), get_lines_between_tags(), get_mtime(), get_unique_string(), grep_file(), is_files_current(), is_path(), paths, search_files(), split_code_file(), touch()

Examples

f1 <- tempfile()
f2 <- tempfile()
try(file_save(f1))
touch(f1)
file_save(f1, recursive = FALSE)
f2 <- paste0(file.path(tempfile()), ".txt")
touch(f2)
file_save(f1, f2)
file_save(f1, f2)
file_save(f1, f2, overwrite = TRUE)
dir(tempdir())

fritools documentation built on Nov. 19, 2023, 1:06 a.m.