Rev 80192 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/unlink.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2021 R Core Team% Distributed under GPL 2 or later\name{unlink}\title{Delete Files and Directories}\usage{unlink(x, recursive = FALSE, force = FALSE, expand = TRUE)}\alias{unlink}\arguments{\item{x}{a character vector with the names of the file(s) ordirectories to be deleted.}\item{recursive}{logical. Should directories be deleted recursively?}\item{force}{logical. Should permissions be changed (if possible) toallow the file or directory to be removed?}\item{expand}{logical. Should wildcards (see \sQuote{Details} below) andtilde (see \code{\link{path.expand}}) be expanded?}}\description{\code{unlink} deletes the file(s) or directories specified by \code{x}.}\details{If \code{recursive = FALSE} directories are not deleted,not even empty ones.#ifdef unixOn most platforms \sQuote{file} includes symbolic links, fifos andsockets. \code{unlink(x, recursive = TRUE)}deletes just the symbolic link if the target of such a link is a directory.#endifWildcard expansion (normally \file{*} and \file{?} are allowed) is done bythe internal code of \code{\link{Sys.glob}}. Wildcards never match aleading \file{.} in the filename, and files \file{.}, \file{..} and\file{~} will never be considered for deletion.#ifdef unixWildcards will only be expanded if the system supports it. Mostsystems will support not only \file{*} and \file{?} but also characterclasses such as \file{[a-z]} (see the \command{man} pages for the systemcall \code{glob} on your OS). The metacharacters \code{* ? [} canoccur 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. Ifa metacharacter matches nothing it is considered as a literalcharacter.\code{recursive = TRUE} might not be supported on all platforms, when itwill be ignored, with a warning: however there are no known currentexamples.#endif#ifdef WindowsCharacter classes such as \file{[a-z]} are supported. Themetacharacter \code{[} can occur in Windows filenames, and this makesit difficult to use \code{unlink} to delete such files (see\code{\link{file.remove}}). If a wildcard matchesnothing it is considered as a literal character.Windows cannot remove the current working directory, nor any filewhich is open nor any directory containing such a file.UTF-8-encoded paths not valid in the current locale can be used, butglobbing will not work.#endif}\value{\code{0} for success, \code{1} for failure, invisibly.Not deleting a non-existent file is not a failure, nor is being unableto delete a directory if \code{recursive = FALSE}. However, missingvalues 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}