Last data update: 2014.03.03

R: Copy a file with a default 'to' name
file.copy2R Documentation

Copy a file with a default 'to' name

Description

Copy a file appending a number to make the to name unique, with default to = from.

Usage

file.copy2(from, to) 

Arguments

from

character: name of a file to be copied

to

character: name of copy. Default = from with an integer appended to the name.

Details

1. length(from) != 1: Error: Only one file can be copied.

2. file.exists(from)? If no, If no, return FALSE.

3. if(missing(to))to <- from; else if(length(to)!=1) error.

4. file.exists(to)? If yes, Dir <- dir(dirname(to)), find all Dir starting with to, and find the smallest integer to append to make a unique to name.

5. file.copy(from, to)

6. Return TRUE.

Value

logical: TRUE (with a name = name of the file created); FALSE if no file created.

Author(s)

Spencer Graves

See Also

file.copy,

Examples

## Not run: 
file.copy2('startup.m')
# Used by 'fdaMatlabPath' so an existing 'startup.m' is not destroyed

## End(Not run)

Results