[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  list.files: List the Files in a Directory/Folder

##  Description

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

##  Usage

    
    
    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)

##  Arguments

path

a character vector of full path names; the default corresponds to the working
directory, ` [ getwd ](/link/getwd?package=base&version=3.6.2) () ` . Tilde
expansion (see ` [ path.expand ](/link/path.expand?package=base&version=3.6.2)
` ) is performed. Missing values will be ignored. Elements with a marked
encoding will be converted to the native encoding.

pattern

an optional [ regular expression
](/link/regular%20expression?package=base&version=3.6.2) . 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 to give a relative file path. If ` FALSE ` , the file names (rather than
paths) are returned.

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 ` "." ` and ` ".." ` be excluded also from non-recursive
listings?

##  Value

A character vector containing the names of the files in the specified
directories (empty if there were no files). If a path does not exist or is not
a directory or is unreadable it is skipped.

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

##  See Also

` [ file.info ](/link/file.info?package=base&version=3.6.2) ` , ` [
file.access ](/link/file.access?package=base&version=3.6.2) ` and ` [ files
](/link/files?package=base&version=3.6.2) ` for many more file handling
functions and ` [ file.choose ](/link/file.choose?package=base&version=3.6.2)
` and ` [ choose.files ](/link/choose.files?package=base&version=3.6.2) ` for
interactive selection.

` [ glob2rx ](/link/glob2rx?package=base&version=3.6.2) ` to convert wildcards
(as used by system file commands and shells) to regular expressions.

` [ Sys.glob ](/link/Sys.glob?package=base&version=3.6.2) ` for wildcard
expansion on file paths.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Flist.files&utm_source=r-docs&utm_medium=docs&utm_term=list.files&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    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)
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversio