1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/copy.R
3\name{copy}
4\alias{copy}
5\alias{file_copy}
6\alias{dir_copy}
7\alias{link_copy}
8\title{Copy files, directories or links}
9\usage{
10file_copy(path, new_path, overwrite = FALSE)
11
12dir_copy(path, new_path, overwrite = FALSE)
13
14link_copy(path, new_path, overwrite = FALSE)
15}
16\arguments{
17\item{path}{A character vector of one or more paths.}
18
19\item{new_path}{A character vector of paths to the new locations.}
20
21\item{overwrite}{Overwrite files if they exist. If this is \code{FALSE} and the
22file exists an error will be thrown.}
23}
24\value{
25The new path (invisibly).
26}
27\description{
28\code{file_copy()} copies files.
29
30\code{link_copy()} creates a new link pointing to the same location as the previous link.
31
32\code{dir_copy()} copies the directory recursively at the new location.
33}
34\details{
35The behavior of \code{dir_copy()} differs slightly than that of \code{file.copy()} when
36\code{overwrite = TRUE}. The directory will always be copied to \code{new_path}, even
37if the name differs from the basename of \code{path}.
38}
39\examples{
40\dontshow{.old_wd <- setwd(tempdir())}
41file_create("foo")
42file_copy("foo", "bar")
43try(file_copy("foo", "bar"))
44file_copy("foo", "bar", overwrite = TRUE)
45file_delete(c("foo", "bar"))
46
47dir_create("foo")
48# Create a directory and put a few files in it
49files <- file_create(c("foo/bar", "foo/baz"))
50file_exists(files)
51
52# Copy the directory
53dir_copy("foo", "foo2")
54file_exists(path("foo2", path_file(files)))
55
56# Create a link to the directory
57link_create(path_abs("foo"), "loo")
58link_path("loo")
59link_copy("loo", "loo2")
60link_path("loo2")
61
62# Cleanup
63dir_delete(c("foo", "foo2"))
64link_delete(c("loo", "loo2"))
65\dontshow{setwd(.old_wd)}
66}
67