1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/delete.R
3\name{delete}
4\alias{delete}
5\alias{file_delete}
6\alias{dir_delete}
7\alias{link_delete}
8\title{Delete files, directories, or links}
9\usage{
10file_delete(path)
11
12dir_delete(path)
13
14link_delete(path)
15}
16\arguments{
17\item{path}{A character vector of one or more paths.}
18}
19\value{
20The deleted paths (invisibly).
21}
22\description{
23\code{file_delete()} and \code{link_delete()} delete file and links. Compared to
24\link{file.remove} they always fail if they cannot delete the object rather than
25changing return value or signalling a warning. If any inputs are
26directories, they are passed to \code{dir_delete()}, so \code{file_delete()} can
27therefore be used to delete any filesystem object.
28
29\code{dir_delete()} will first delete the contents of the directory, then remove
30the directory. Compared to \link{unlink} it will always throw an error if the
31directory cannot be deleted rather than being silent or signalling a warning.
32}
33\examples{
34\dontshow{.old_wd <- setwd(tempdir())}
35# create a directory, with some files and a link to it
36dir_create("dir")
37files <- file_create(path("dir", letters[1:5]))
38link <- link_create(path_abs("dir"), "link")
39
40# All files created
41dir_exists("dir")
42file_exists(files)
43link_exists("link")
44file_exists(link_path("link"))
45
46# Delete a file
47file_delete(files[1])
48file_exists(files[1])
49
50# Delete the directory (which deletes the files as well)
51dir_delete("dir")
52file_exists(files)
53dir_exists("dir")
54
55# The link still exists, but what it points to does not.
56link_exists("link")
57dir_exists(link_path("link"))
58
59# Delete the link
60link_delete("link")
61link_exists("link")
62\dontshow{setwd(.old_wd)}
63}
64