ID EN
I/O & Files

files2

R Base 3.6.2

These functions provide a low-level interface to the computer's file system.

Syntax

R
dir.exists(paths)
dir.create(path, showWarnings = TRUE, recursive = FALSE, mode = "0777")
Sys.chmod(paths, mode = "0777", use_umask = TRUE)
Sys.umask(mode = NA)

Arguments

Parameter Description
path a character vector containing a single path name. Tilde expansion (see path.expand) is done.
paths character vectors containing file or directory paths. Tilde expansion (see path.expand) is done.
showWarnings logical; should the warnings on failure be shown?
recursive logical. Should elements of the path other than the last be created? If true, like the Unix command mkdir -p.
mode the mode to be used on Unix-alikes: it will be coerced by as.octmode. For Sys.chmod it is recycled along paths.
use_umask logical: should the mode be restricted by the umask setting?

Return Value

dir.exists returns a logical vector of TRUE or FALSE values (without names). dir.create and Sys.chmod return invisibly a logical vector indicating if the operation succeeded for each of the files attempted. Using a missing value for a path name will always be regarded as a failure. dir.create indicates failure if the directory already exists. If showWarnings = TRUE, dir.create will give a warning for an unexpected failure (e.g., not for a missing value nor for an already existing component for r

Details

dir.create creates the last element of the path, unless recursive = TRUE. Trailing path separators are discarded. On Windows drives are allowed in the path specification and unless the path is rooted, it will be interpreted relative to the current directory on that drive. mode is ignored on Windows. The mode will be modified by the umask setting in the same way as for the system function mkdir. What modes can be set is OS-dependent, and it is unsafe to assume that more than three octal digits will be used. For more details see your OS's documentation on the system call mkdir, e.g.man 2 mkdir (and not that on the command-line utility of that name). One of the idiosyncrasies of Windows is that directory creation may report success but create a directory with a different name, for example dir

Examples

Example
R
# NOT RUN {
## Fix up maximal allowed permissions in a file tree
Sys.chmod(list.dirs("."), "777")
f <- list.files(".", all.files = TRUE, full.names = TRUE, recursive = TRUE)
Sys.chmod(f, (file.info(f)$mode | "664"))
# }

See Also

file.info file.exists file.path list.files unlink basename path.expand.