list.files {base}R Documentation

List the Files in a Directory/Folder


These functions produce a character vector of the names of files in the named directory.


list.files(path = ".", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE)
       dir(path = ".", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE)


path a character vector of full path names; the default corresponds to the working directory getwd().
pattern an optional regular expression. Only file names which match the regular expression will be returned.
all.files a logical value. If FALSE, only the names of visible files are returned. If TRUE, all file names will be returned.
full.names a logical value. If TRUE, the directory path is prepended to the file names. If FALSE, only the file names are returned.
recursive logical. Should the listing recurse into directories?


A character vector containing the names of the files in the specified directories, or "" if there were no files. If a path does not exist or is not a directory or is unreadable it is skipped, with a warning.
The files are sorted in alphabetical order, on the full path if full.names = TRUE.


File naming conventions are very platform dependent.

recursive = TRUE is not supported on all platforms, and may be ignored, with a warning.


Ross Ihaka, Brian Ripley

See Also, file.access and files for many more file handling functions and file.choose for interactive selection.

glob2rx to convert wildcards (as used by system file commands and shells) to regular expressions.

Sys.glob for wildcard expansion on file paths.


## Only files starting with a-l or r
dir("../..", pattern = "^[a-lr]",full.names=TRUE)

[Package base version 2.5.0 Index]