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