| 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{ |
| 10 |
file_delete(path) |
| 11 |
|
| 12 |
dir_delete(path) |
| 13 |
|
| 14 |
link_delete(path) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{path}{A character vector of one or more paths.} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
The 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 |
| 25 |
changing return value or signalling a warning. If any inputs are |
| 26 |
directories, they are passed to \code{dir_delete()}, so \code{file_delete()} can |
| 27 |
therefore be used to delete any filesystem object. |
| 28 |
|
| 29 |
\code{dir_delete()} will first delete the contents of the directory, then remove |
| 30 |
the directory. Compared to \link{unlink} it will always throw an error if the |
| 31 |
directory 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 |
| 36 |
dir_create("dir") |
| 37 |
files <- file_create(path("dir", letters[1:5])) |
| 38 |
link <- link_create(path_abs("dir"), "link") |
| 39 |
|
| 40 |
# All files created |
| 41 |
dir_exists("dir") |
| 42 |
file_exists(files) |
| 43 |
link_exists("link") |
| 44 |
file_exists(link_path("link")) |
| 45 |
|
| 46 |
# Delete a file |
| 47 |
file_delete(files[1]) |
| 48 |
file_exists(files[1]) |
| 49 |
|
| 50 |
# Delete the directory (which deletes the files as well) |
| 51 |
dir_delete("dir") |
| 52 |
file_exists(files) |
| 53 |
dir_exists("dir") |
| 54 |
|
| 55 |
# The link still exists, but what it points to does not. |
| 56 |
link_exists("link") |
| 57 |
dir_exists(link_path("link")) |
| 58 |
|
| 59 |
# Delete the link |
| 60 |
link_delete("link") |
| 61 |
link_exists("link") |
| 62 |
\dontshow{setwd(.old_wd)} |
| 63 |
} |