ctime_filt: Filter files by c/m/atime

View source: R/ctime_filt.R

ctime_filtR Documentation

Filter files by c/m/atime

Description

Identify earliest or latest file(s) by creation/modified/access time

Usage

ctime_filt(
  x,
  pattern,
  type = c("max", "min"),
  what_finfo = c("ctime", "mtime", "atime"),
  only_last = TRUE,
  fmt = "%Y-%m-%d",
  print_limit = 6L,
  ...
)

Arguments

x

Input file path

pattern

Optional regex passed to list.files pattern arg; defaults to .* (any).

type

One of "min" or "max" (quotes explicit) to denote if function should find earliest or latest file by file.info file time, respectively. Defaults to "max" (most recent file(s)); see what_finfo.

what_finfo

What file.info field type should be used for filtering? Defaults to ctime.

only_last

Should only the last file found be returned? Defaults to TRUE

fmt

character date format for ctime transformation. Defaults to %Y-%m-%d

print_limit

Optional integer. How many found results should be printed? Defaults to 6. This ONLY affects display results, NOT returned results!

...

Other arguments to pass to list.files, aside from pattern

Details

This is most useful for filtering out multiple files with similar or identical file names within a single parent dir, regardless of nesting, by one of ctime,mtime,atime as denoted by file.info. By default, the timestamp used is ctime.

Beware if using directly for reading-in, as this function will list all files found according to input criteria, although it will also return only the last file found, by default. Nonetheless, you should apply additional constraints for non-interactive use, e.g. specifying a more specific path and/or pattern.

Value

A vector of files (full path names) that meet the type criteria (earliest or latest) and any other constraints, within the scope of the specified dir.

Examples

x <- list.files(R.home("doc"), full.names = TRUE)
ctime_filt(x) #use defaults
ctime_filt(x, pattern = ".html|.png", type = "max")

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.