unlink.Rd 3.11 KB
Newer Older
Radford Neal's avatar
Radford Neal committed
1 2
% File src/library/base/man/unlink.Rd
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2011 R Core Team
Radford Neal's avatar
Radford Neal committed
4 5 6 7
% Distributed under GPL 2 or later

\name{unlink}
\title{Delete Files and Directories}
Radford Neal's avatar
Radford Neal committed
8
\usage{unlink(x, recursive = FALSE, force = FALSE)}
Radford Neal's avatar
Radford Neal committed
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's avatar
Radford Neal committed
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's avatar
Radford Neal committed
17 18 19 20 21
}
\description{
  \code{unlink} deletes the file(s) or directories specified by \code{x}.
}
\details{
Radford Neal's avatar
Radford Neal committed
22
  Tilde-expansion (see \code{\link{path.expand}}) is done on \code{x}.
Radford Neal's avatar
Radford Neal committed
23
  
Radford Neal's avatar
Radford Neal committed
24 25 26 27
  If \code{recursive = FALSE} directories are not deleted,
  not even empty ones.

#ifdef unix
Radford Neal's avatar
Radford Neal committed
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's avatar
Radford Neal committed
33
  
Radford Neal's avatar
Radford Neal committed
34
#endif  
Radford Neal's avatar
Radford Neal committed
35
  Wildcard expansion is done by the internal code of
Radford Neal's avatar
Radford Neal committed
36
  \code{\link{Sys.glob}}.  Wildcards never match a leading \file{.} in
Radford Neal's avatar
Radford Neal committed
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's avatar
Radford Neal committed
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's avatar
Radford Neal committed
49

Radford Neal's avatar
Radford Neal committed
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's avatar
Radford Neal committed
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's avatar
Radford Neal committed
63 64
  
  UTF-8-encoded paths not valid in the current locale can be used.
Radford Neal's avatar
Radford Neal committed
65 66 67
#endif
}
\value{
Radford Neal's avatar
Radford Neal committed
68
  \code{0} for success, \code{1} for failure, invisibly.
Radford Neal's avatar
Radford Neal committed
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}