Rev 44765 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/files.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2008 R Core Development Team% Distributed under GPL 2 or later\name{files}\alias{files}\concept{directory}\title{File and Directory Manipulation}\usage{file.create(\dots, showWarnings = TRUE)file.exists(\dots)file.remove(\dots)file.rename(from, to)file.append(file1, file2)file.copy(from, to, overwrite = FALSE)file.symlink(from, to)dir.create(path, showWarnings = TRUE, recursive = FALSE,mode = "0777")Sys.chmod(paths, mode = "0777")Sys.umask(mode = "0000")}\alias{file.append}\alias{file.copy}\alias{file.create}\alias{file.exists}\alias{file.remove}\alias{file.rename}\alias{file.symlink}\alias{dir.create}\alias{Sys.chmod}\alias{Sys.umask}\arguments{\item{\dots, file1, file2, from, to, paths}{character vectors,containing file names or paths.}\item{path}{a character vector containing a single path name.}\item{overwrite}{logical; should the destination files be overwritten?}\item{showWarnings}{logical; should the warnings on failure be shown?}\item{recursive}{logical: should elements of the path other than thelast be created? If true, like Unix's \code{mkdir -p}.}\item{mode}{the file mode to be used on Unix-alikes: it will becoerced by \code{\link{as.octmode}}.}}\description{These functions provide a low-level interface to the computer'sfile system.}\details{The \code{\dots} arguments are concatenated to form one characterstring: you can specify the files separately or as one vector.All of these functions expand path names: see \code{\link{path.expand}}.\code{file.create} creates files with the given names if they do notalready exist and truncates them if they do. They are created with themaximal permissions allowed by the \code{umask} setting.\code{file.exists} returns a logical vector indicating whetherthe files named by its argument exist. (Here \sQuote{exists} is in thesense of the system's \code{stat} call: a file will be reported asexisting only if you have the permissions needed by \code{stat}.Existence can also be checked by \code{\link{file.access}}, whichmight use different permissions and so obtain a different result.Note that the existence of a file does not imply that it is readable:for that use \code{\link{file.access}}.)\code{file.remove} attempts to remove the files named in itsargument.#ifdef unixOn most platforms \sQuote{file} includes \emph{empty} directories,symbolic links, fifos and sockets.#endif#ifdef windowsUnlike on Unix-alikes, \sQuote{file} here means a regular file andnot, say, an empty directory.#endif\code{file.rename} attempts to rename a single file.\code{file.append} attempts to append the files named by itssecond argument to those named by its first. The \R subscriptrecycling rule is used to align names given in vectorsof different lengths.\code{file.copy} works in a similar way to \code{file.append} but withthe arguments in the natural order for copying. Copying to existingdestination files is skipped unless \code{overwrite = TRUE}.The \code{to} argument can specify a single existing directory.\code{file.symlink} makes symbolic links on those Unix-like platformswhich support them. The \code{to} argument can specify a singleexisting directory.#ifdef windows(Windows Vista/Server 2008 have a version of symbolic links on NTFSfilesystems, but this seems too limited to be worth implementing.)#endif\code{dir.create} creates the last element of the path, unless\code{recursive = TRUE}. Trailing path separators are removed.#ifdef windowsOn Windows drives are allowed in the path specification and unlessthe path is rooted, it will be interpreted relative to the currentdirectory on that drive. \code{mode} is ignored on Windows.#endif#ifdef unixThe mode will be modified by the \code{umask} setting in the same wayas for the system function \code{mkdir}. What modes can be set isOS-dependent, and it is unsafe to assume that more than three octaldigits will be used. For more details see your OS's documentation on thesystem call \code{mkdir} (and not that on the command-line utility ofthat name).#endif\code{Sys.chmod} sets the file permissions of one or more files.#ifdef unixIt may not be supported (when a warning is issued).See the comments for \code{dir.create} for how modes are interpreted.Changing mode on a symbolic link is unlikely to work (nor benecessary). For more details see your OS's documentation on thesystem call \code{chmod} (and not that on the command-line utility ofthat name).#endif#ifdef windowsThe interpretation of \code{mode} in the Windows system function isnon-POSIX and only supports setting the read-only attribute of thefile. So \R interprets \code{mode} to mean set read-only if and onlyif \code{mode & 0200 == 0} (interpreted in octal). Windows has a muchmore extensive system of file permissions on some file systems(e.g. versions of NTFS) which are unrelated to this system call.#endif\code{Sys.umask} sets the \code{umask}.#ifdef unixIt may not be supported (when a warning is issued and \code{"0000"}returned). For more details see your OS's documentation on thesystem call \code{umask}.#endif#ifdef windowsAll files on Windows are readable, and files being executable is not aWindows concept. So \code{umask} only controls whether a file iswritable: a setting of \code{"200"} makes files (but not directories)created subsequently read-only.#endif}\value{\code{dir.create} and \code{file.rename} return a logical,true for success.\code{Sys.umask} returns the previous value of the \code{umask},invisibly, as a length-one object of class \code{"octmode"}.The remaining functions return a logical vector indicating whichoperation succeeded for each of the files attempted.\code{dir.create} will return failure if the directory already exists.If \code{showWarnings = TRUE}, \code{file.create} and\code{dir.create} will give a warning for an unexpected failure(e.g. not for a missing value nor for an already existing component for\code{dir.create(recursive = TRUE)}).Using a missing value for a file or path name will always be regardedas a failure.}\author{Ross Ihaka, Brian Ripley}\seealso{\code{\link{file.info}}, \code{\link{file.access}}, \code{\link{file.path}},\code{\link{file.show}}, \code{\link{list.files}},\code{\link{unlink}}, \code{\link{basename}}, \code{\link{path.expand}}.\code{\link{file_test}}.}\examples{cat("file A\n", file="A")cat("file B\n", file="B")file.append("A", "B")file.create("A")file.append("A", rep("B", 10))if(interactive()) file.show("A")file.copy("A", "C")dir.create("tmp")file.copy(c("A", "B"), "tmp")list.files("tmp")#ifdef unixsetwd("tmp")file.remove("B")file.symlink(file.path("..", c("A", "B")), ".")setwd("..")#endifunlink("tmp", recursive=TRUE)file.remove("A", "B", "C")}\keyword{file}