List the Files in a Directory.

DESCRIPTION:

Lists the names of the files in the specified directory (or directories) or, if no directory path is specified, the current directory. dir is another way to invoke list.files .

USAGE:

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>>, ...)

OPTIONAL ARGUMENTS:

path
a character vector of path names. The default corresponds to the working directory 'getwd()'. If more than one directory path is specified, the returned list is a concatenation of the contents of each directory.
pattern
a character string containing a regular expression. If the basename of a file matches the regular expression, it will be returned. See the regexpr function for details on regular expressions.
all.files
a logical value. If TRUE the entire contents of directory are listed, otherwise only visible (non-hidden) file or directory names are returned. Hidden files or directories are those with names that begin with a period.
full.names
a logical value. If TRUE, the directory path is prepended to the returned names. If FALSE, only the file or directory name is in the return value.
recursive
a logical value. If 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.
type
a character string that controls whether directory names, file names, or both are returned. Possible values are: "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.
...
used for additional arguments that are send to the 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.

VALUE:

a character vector containing the names of the contents of the specified directories sorted in alphabetical order. If a directory is empty or if an unreadable or nonexistent directory path is specified then an empty character vector is returned. In the latter case, a warning message will appear.

DETAILS:

File naming conventions are platform dependent.

This function emulates R's list.files function but includes an extra argument, type.

SEE ALSO:

, , , , , .

EXAMPLES:

# 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")