list.files2: List the Files in a Directory/Folder

list.files2R Documentation

List the Files in a Directory/Folder

Description

On Windows, when the C runtime is not "ucrt", list.files2 and list.dirs2 list all the files or directories in UTF-8 rather than the native encoding. It uses jsonlite and python, so make sure you have them installed.

Otherwise, list.files2 and list.dirs2 will just call list.files.

Usage

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

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

list.dirs2(path = ".", full.names = TRUE, recursive = TRUE)

Arguments

path, pattern, all.files, full.names, recursive, ignore.case, include.dirs, no..

See list.files.

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.

list.dirs2 implicitly has all.files = TRUE, and if recursive = TRUE, the answer includes path itself (provided it is a readable directory).

dir2 is an alias for list.files2.

See Also

list.files

Examples

list.files2(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
dir2("../..", pattern = "^[a-lr]", full.names = TRUE, ignore.case = TRUE)

list.dirs2(R.home("doc"))
list.dirs2(R.home("doc"), full.names = FALSE)


## in Windows without Universal C Runtime, 'list.files' returns
## a mis-translated filename whereas 'list.files2' does not

dir.create(DIR <- tempfile("dir"))
invisible(file.create(file.path(DIR, "testing_\u{03B4}.txt")))


file.exists(list.files (DIR, full.names = TRUE))
file.exists(list.files2(DIR, full.names = TRUE))


unlink(DIR, recursive = TRUE)

ArcadeAntics/essentials documentation built on Nov. 7, 2024, 4:33 p.m.