Skip to contents

Adds a timestamp to a file

Usage

add_file_timestamp(
  x,
  ts = Sys.time(),
  format = "%Y-%m-%d %H%M%S",
  sep = " "
)

Arguments

x

A vector of files

ts

A single timestamp or vector of timestamps (default: Sys.time())

format

A format to be applied to the times; set to NULL to skip formatting

sep

A character vector of length 1 to separate the timestamp from the file name

Value

The full name paths with the appended time stamp

Examples

file1 <- tempfile(fileext = ".txt")
file2 <- tempfile()

add_file_timestamp(file1)
#> /tmp/RtmpCqf6lt/file1c4d4f1cd215 2025-04-26 154046.txt
add_file_timestamp(file2)
#> /tmp/RtmpCqf6lt/file1c4d4779971e 2025-04-26 154046

file.remove(file1, file2)
#> Warning: cannot remove file '/tmp/RtmpCqf6lt/file1c4d4f1cd215.txt', reason 'No such file or directory'
#> Warning: cannot remove file '/tmp/RtmpCqf6lt/file1c4d4779971e', reason 'No such file or directory'
#> [1] FALSE FALSE