dir
is another way to invoke
list.files
.
list.files(path=".", pattern=NULL, all.files=FALSE, full.names=FALSE, recursive=FALSE, type=<<see below>>, ...) dir(path=".", pattern=NULL, all.files=FALSE, full.names=FALSE, recursive=FALSE, type=<<see below>>, ...)
regexpr
function for details on regular expressions.
TRUE
, the file names in all directory paths are
recursively listed.
When
recursive=T
,
the names of subdirectories are not returned, but
the
type
argument can be used to
change that behavior.
"files"
, return only file names;
"directories"
, return only directory names; or
"all"
, return both. This argument is not
in R's version of this function. The default value
is dependent on the value of
recursive
in order to agree with R's list.files which does not include directories
when
recursive=T
but does otherwise.
regexpr
function when the
pattern
argument is used.
These are all logical valued and must be specified by name.
See the
extended
,
fixed,
ignore.case,
and
perl
arguments to the
regexpr
function.
File naming conventions are platform dependent.
This function emulates R's
list.files
function but includes an extra argument,
type
.
# Should return TRUE: all.equal(list.files(all.files=T), files.in.dir())
# Do a recursive listing of the current directory, including # both file and directory names dir(recursive=T, type="all")
# Find all files whose names start with 'x' that are in all .Data # directories somewhere under the current directory. # First find all .Data directories. Set all.files=TRUE to get hidden names. dot.data.dirs <- list.files(".", type="directories", pattern="^\\.Data$", recursive=TRUE, full.names=TRUE, all.files=TRUE) # Now find all files having names beginning with 'x' list.files(dot.data.dirs, pattern="^x", full.names=TRUE, type="files")