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

Tomas Kalibera tomas.kalibera at gmail.com
Tue Apr 10 01:03:29 CEST 2018


Thanks for the report, fixed in R-devel. Now we get a warning when 
copying a directory over a non-directory file is attempted. The target 
(non-directory) file is left alone.

Tomas

On 09/08/2017 06:54 PM, William Dunlap via R-devel wrote:
> 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]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list