list.files
List the Files in a Directory

Description

Lists the names of the files in the specified directory (or directories). If no directory path is specified, lists the current directory. You can use dir as an alternative to invoking list.files.

Usage

list.files(path = ".", pattern = NULL, all.files = FALSE, 
    full.names = FALSE, recursive = FALSE, ignore.case = FALSE, 
    include.dirs = FALSE, no.. = TRUE)
dir(path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, 
    recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, no.. = TRUE)
list.dirs(path = ".", full.names = TRUE, recursive = TRUE) 

Arguments

path a character vector of path names. The default corresponds to the working directory returned by getwd(). You can specify more than one directory path.
pattern a character string containing a regular expression. If the basename of a file matches the regular expression, it is returned. See the regexpr function for details on regular expressions. By default, NULL, specifying returning all files found in path.
all.files a logical value. If TRUE, the entire contents of directory are returned. If FALSE (the default, 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 (the default), 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 listed recursively. When include.dirs=TRUE, the names of subdirectories are also returned. The default is FALSE.
ignore.case a logical value. If TRUE, uppercase and lowercase characters are considered equivalent when matching. The default is FALSE.
include.dirs a logical value. Only used when recursive=TRUE. If TRUE, both names of files and subdirectories are returned. Otherwise, only names of files are returned.
no.. a logical value. This argument is ignored. Unlike R, list.files and dir will not include the special directory entries "." and ".." in their lists of items in a directory.

Details

File naming conventions are platform-dependent. Function list.dirs is used to list all directory paths in specify path.
Value
returns a character vector containing the names of the contents of the specified directories, sorted in alphabetical order.
If you specify more than one directory for path, the returned list is a concatenation of the contents of each directory.
If a directory is empty, or if an unreadable or nonexistent directory path is specified, then this function returns an empty character vector.
Differences between TIBCO Enterprise Runtime for R and Open-source R
Both TIBCO Enterprise Runtime for R and open-source R sort files depending on locale. In the "C" locale (e.g., Sys.setlocale(locale='C')), characters are sorted by their ascii codes. As a result, in TIBCO Enterprise Runtime for R, the list.files function lists all files starting with upper case before listing files starting with lower case. In open-source R, list.files lists files ignoring the case.
See Also
dir.create, file.info, path.expand, file.access, regexpr.
Examples
# Do a recursive listing of the TERR doc directory, including
# both file and directory names
dir(R.home("doc"), recursive = TRUE, include.dirs=TRUE)

# Find possible TERR or R startup files dir(c("~", R.home("etc"), getwd()), pattern="Rprofile\\>", all.files=TRUE, full.names=TRUE)

# Find all directories called 'Meta' in the TERR library directory Meta.dirs <- list.dirs(R.home("library"), full.names=TRUE) Meta.dirs <- Meta.dirs[grep(pattern="^Meta$", basename(Meta.dirs))] head(Meta.dirs) # Find all '.rds' files in those Meta directories Meta.rds.files <- list.files(Meta.dirs, pattern="\\.rds", full.names=TRUE) head(Meta.rds.files)

Package base version 6.0.0-69
Package Index