From wdunlap at tibco.com  Fri Sep  8 18:54:58 2017
From: wdunlap at tibco.com (William Dunlap)
Date: Fri, 8 Sep 2017 09:54:58 -0700
Subject: [Rd] file.copy(from=Directory, to=File) oddity
Message-ID: <CAF8bMcaP2dHS3KAZVyXifuigZ3B2LmoR6N+=vdzBaCF5svGrhg@mail.gmail.com>

When I mistakenly use file.copy() with a directory for the 'from' argument
and a non-directory for the 'to' and overwrite=TRUE, file.copy returns
FALSE, meaning it could not do the copying.  However, it also replaces the
'to' file with a zero-length file.

dir.create( fromDir <- tempfile() )
cat(file = toFile <- tempfile(), "existing file\n")
readLines(toFile)
#[1] "existing file"
file.copy(fromDir, toFile, recursive=FALSE, overwrite=TRUE)
#[1] FALSE
readLines(toFile)
#character(0)

or, with recursive=TRUE,

dir.create( fromDir <- tempfile() )
cat(file = toFile <- tempfile(), "existing file\n")
readLines(toFile)
#[1] "existing file"
file.copy(fromDir, toFile, recursive=TRUE, overwrite=TRUE)
#[1] FALSE
#Warning message:
#In file.copy(fromDir, toFile, recursive = TRUE, overwrite = TRUE) :
#  'recursive' will be ignored as 'to' is not a single existing directory
readLines(toFile)
#character(0)

Is this behavior intended?

Bill Dunlap
TIBCO Software
wdunlap tibco.com

	[[alternative HTML version deleted]]



[Rd] file.copy(from=Directory, to=File) oddity
William Dunlap