Detect which files have changed
fileSnapshot takes a snapshot of a selection of files,
recording summary information about each.
compares two snapshots, or compares one snapshot to the current state
of the file system. The snapshots need not be the same directory;
this could be used to compare two directories.
fileSnapshot(path = ".", file.info = TRUE, timestamp = NULL, md5sum = FALSE, digest = NULL, full.names = length(path) > 1, ...)changedFiles(before, after, path = before$path, timestamp = before$timestamp, check.file.info = c("size", "isdir", "mode", "mtime"), md5sum = before$md5sum, digest = before$digest, full.names = before$full.names, ...) "print"(x, verbose = FALSE, ...)"print"(x, verbose = FALSE, ...)
- character vector; the path(s) to record.
- logical; whether to record
file.infovalues for each file.
- character string or
NULL; the name of a file to write at the time the snapshot is taken. This gives a quick test for modification, but may be unreliable; see the Details.
- logical; whether MD5 summaries of each file should be taken as part of the snapshot.
- a function or
NULL; a function with header
function(filename)which will take a vector of filenames and produce a vector of values of the same length, or a matrix with that number of rows.
- logical; whether full names (as in
list.files) should be recorded. Must be
length(path) > 1.
- additional parameters to pass to
list.filesto control the set of files in the snapshots.
- before, after
- objects produced by
fileSnapshot; two snapshots to compare. If
afteris missing, a new snapshot of the current file system will be produced for comparison, using arguments recorded in
- character vector; which columns from
file.infoshould be compared.
- the object to print.
- logical; whether to list all data when printing.
fileSnapshot function uses
obtain a list of files, and depending on the
digest arguments, records information about
changedFiles function compares two snapshots.
timestamp argument to
fileSnapshot is length 1, a
file with that name is created. If it is length 1 in
file_test function is used to
compare the age of all files common to both
after to it. This test may be unreliable: it compares the
current modification time of the
after files to the timestamp;
that may not be the same as the modification time when the
after snapshot was taken. It may also give incorrect results
if the clock on the file system holding the timestamp differs from the
one holding the snapshot files.
check.file.info argument contains a non-empty character
vector, the indicated columns from the result of a call to
file.info will be compared.
fileSnapshot will call the
tools::md5sum function to record the 32 byte MD5
checksum for each file, and
changedFiles will compare the
digest argument allows users to provide their own
- a data frame whose rownames are the filenames, and whose columns contain the requested snapshot data
- the normalized
pathfrom the call
- timestamp, file.info, md5sum, digest, full.names
- a record of the other arguments from the call
- other arguments passed via
- added, deleted, changed, unchanged
- character vectors of filenames from the before and after snapshots, with obvious meanings
- a logical matrix with a row for each common file, and a
column for each comparison test.
TRUEindicates a change in that test.
fileSnapshotreturns an object of class
"fileSnapshot". This is a list containing the fields
changedFilesproduces an object of class
"changedFiles". This is a list containing
"fileSnapshot"objects displays the arguments used to produce them, while the one for
changedfields if non-empty, and a submatrix of the
changesmatrix containing all of the
# Create some files in a temporary directory dir <- tempfile() dir.create(dir) writeBin(1L, file.path(dir, "file1")) writeBin(2L, file.path(dir, "file2")) dir.create(file.path(dir, "dir")) # Take a snapshot snapshot <- fileSnapshot(dir, timestamp = tempfile("timestamp"), md5sum=TRUE) # Change one of the files. writeBin(3L:4L, file.path(dir, "file2")) # Display the detected changes. We may or may not see mtime change... changedFiles(snapshot) changedFiles(snapshot)$changes