Radford Neal committed May 18, 2013 1 2 % File src/library/base/man/unlink.Rd % Part of the R package, http://www.R-project.org  Radford Neal committed Aug 26, 2016 3 % Copyright 1995-2011 R Core Team  Radford Neal committed May 18, 2013 4 5 6 7 % Distributed under GPL 2 or later \name{unlink} \title{Delete Files and Directories}  Radford Neal committed May 18, 2013 8 \usage{unlink(x, recursive = FALSE, force = FALSE)}  Radford Neal committed May 18, 2013 9 10 11 12 13 \alias{unlink} \arguments{ \item{x}{a character vector with the names of the file(s) or directories to be deleted. Wildcards (normally \file{*} and \file{?}) are allowed.}  Radford Neal committed May 18, 2013 14 15 16  \item{recursive}{logical. Should directories be deleted recursively?} \item{force}{logical. Should permissions be changed (if possible) to allow the file or directory to be removed?}  Radford Neal committed May 18, 2013 17 18 19 20 21 } \description{ \code{unlink} deletes the file(s) or directories specified by \code{x}. } \details{  Radford Neal committed May 18, 2013 22  Tilde-expansion (see \code{\link{path.expand}}) is done on \code{x}.  Radford Neal committed May 18, 2013 23   Radford Neal committed May 18, 2013 24 25 26 27  If \code{recursive = FALSE} directories are not deleted, not even empty ones. #ifdef unix  Radford Neal committed May 18, 2013 28 29 30 31 32  On most platforms \sQuote{file} includes symbolic links, fifos and sockets. Prior to \R 2.15.0 \code{unlink(x, recursive = TRUE)} would delete the contents of a directory target of a symbolic link: it now only deletes the symbolic link (as \code{unlink(x, recursive = FALSE)} always has).  Radford Neal committed May 18, 2013 33   Radford Neal committed May 18, 2013 34 #endif  Radford Neal committed May 18, 2013 35  Wildcard expansion is done by the internal code of  Radford Neal committed May 18, 2013 36  \code{\link{Sys.glob}}. Wildcards never match a leading \file{.} in  Radford Neal committed May 18, 2013 37 38 39 40  the filename, and files \file{.} and \file{..} will never be considered for deletion. #ifdef unix Wildcards will only be expanded if the system supports it. Most  Radford Neal committed May 18, 2013 41 42 43 44 45 46 47 48  systems will support not only \file{*} and \file{?} but also character classes such as \file{[a-z]} (see the \command{man} pages for the system call \code{glob} on your OS). The metacharacters \code{* ? [} can occur in Unix filenames, and this makes it difficult to use \code{unlink} to delete such files (see \code{\link{file.remove}}), although escaping the metacharacters by backslashes usually works. If a metacharacter matches nothing it is considered as a literal character.  Radford Neal committed May 18, 2013 49   Radford Neal committed May 18, 2013 50 51 52  \code{recursive = TRUE} might not be supported on all platforms, when it will be ignored, with a warning: however there are no known current examples.  Radford Neal committed May 18, 2013 53 54 55 56 57 58 59 60 61 62 #endif #ifdef Windows Character classes such as \file{[a-z]} are supported. The metacharacter \code{[} can occur in Windows filenames, and this makes it difficult to use \code{unlink} to delete such files (see \code{\link{file.remove}}). If a wildcard matches nothing it is considered as a literal character. Windows cannot remove the current working directory, nor any file which is open nor any directory containing such a file.  Radford Neal committed May 18, 2013 63 64  UTF-8-encoded paths not valid in the current locale can be used.  Radford Neal committed May 18, 2013 65 66 67 #endif } \value{  Radford Neal committed May 18, 2013 68  \code{0} for success, \code{1} for failure, invisibly.  Radford Neal committed May 18, 2013 69 70 71 72 73 74 75 76 77 78 79 80 81 82  Not deleting a non-existent file is not a failure, nor is being unable to delete a directory if \code{recursive = FALSE}. However, missing values in \code{x} are regarded as failures. } \references{ Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) \emph{The New S Language}. Wadsworth & Brooks/Cole. } \seealso{ \code{\link{file.remove}}. } %Examples: tempfile has an 'unlink' example \keyword{file}