Description Usage Arguments Value Note Author(s) See Also Examples
These functions produce a character vector of the names of files or directories in the named directory.
1 2 3 4 5 6 7 8 9 | list.files(path = ".", pattern = NULL, all.files = FALSE,
full.names = FALSE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
dir(path = ".", pattern = NULL, all.files = FALSE,
full.names = FALSE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
list.dirs(path = ".", full.names = TRUE, recursive = TRUE)
|
path |
a character vector of full path names; the default
corresponds to the working directory, |
pattern |
an optional regular expression. Only file names which match the regular expression will be returned. |
all.files |
a logical value. If |
full.names |
a logical value. If |
recursive |
logical. Should the listing recurse into directories? |
ignore.case |
logical. Should pattern-matching be case-insensitive? |
include.dirs |
logical. Should subdirectory names be included in recursive listings? (They always are in non-recursive ones). |
no.. |
logical. Should both |
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
.
list.dirs
implicitly has all.files = TRUE
, and if
recursive = TRUE
, the answer includes path
itself
(provided it is a readable directory).
File naming conventions are platform dependent. The pattern matching works with the case of file names as returned by the OS.
On a POSIX filesystem recursive listings will follow symbolic links to directories.
Ross Ihaka, Brian Ripley
file.info
, 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.
1 2 3 4 5 6 7 8 | list.files(R.home())
## Only files starting with a-l or r
## Note that a-l is locale-dependent, but using case-insensitive
## matching makes it unambiguous in English locales
dir("../..", pattern = "^[a-lr]", full.names = TRUE, ignore.case = TRUE)
list.dirs(R.home("doc"))
list.dirs(R.home("doc"), full.names = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.