fileSnapshot
takes a snapshot of a selection of files,
recording summary information about each. changedFiles
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, ...)
file.info
values for each file.
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. 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. list.files
) should be recorded. Must be TRUE
if
length(path) > 1
. list.files
to control the set of files in the snapshots.
fileSnapshot
; two
snapshots to compare. If after
is missing, a new snapshot of
the current file system will be produced for comparison, using
arguments recorded in before
as defaults. file.info
should be compared. fileSnapshot
returns an object of class "fileSnapshot"
.
This is a list containing the fieldspath
from the call...
to
list.files
.changedFiles
produces an object of class "changedFiles"
.
This is a list containingTRUE
indicates a change in
that test.print
methods are defined for each of these types. The
print
method for "fileSnapshot"
objects
displays the arguments used to produce them, while the one for
"changedFiles"
displays the added
, deleted
and
changed
fields if non-empty, and a submatrix of the
changes
matrix containing all of the TRUE
values.The fileSnapshot
function uses list.files
to
obtain a list of files, and depending on the file.info
,
md5sum
, and digest
arguments, records information about
each file.
The changedFiles
function compares two snapshots.
If the timestamp
argument to fileSnapshot
is length 1, a
file with that name is created. If it is length 1 in
changedFiles
, the file_test
function is used to
compare the age of all files common to both before
and
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.
If the 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.
If md5sum
is TRUE
, fileSnapshot
will call the
tools::md5sum
function to record the 32 byte MD5
checksum for each file, and changedFiles
will compare the
values. The digest
argument allows users to provide their own
digest function.
file.info
, file_test
, md5sum
.
# 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
Run the code above in your browser using DataLab