file.copy
File and Directory Manipulation

Description

These functions provide file and directory manipulation from within Spotfire Enterprise Runtime for R. They can check for file existence; they can create, copy, rename, or remove files; and they can append to files and create directories.

Usage

file.create(..., showWarnings = TRUE)
file.exists(...)
file.remove(...)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite = recursive, recursive = FALSE,
          copy.mode = TRUE, copy.date = FALSE)
file.symlink(from, to)
file.link(from, to)
dir.create(path, showWarnings = TRUE, recursive = FALSE, mode = "0777")
dir.exists(paths)
Sys.readlink(paths)

Arguments

..., from, to, file1, file2 character vectors containing file names. The ... arguments are concatenated to form one vector of character values.
showWarnings a logical value. If TRUE (the default), then warnings on file or directory creation are displayed.
overwrite a logical value. If TRUE, then the destination file(s) are overwritten if they exist. By default, FALSE.
recursive a logical value. If TRUE, then all elements in path are created if they do not already exist. By default, FALSE.
copy.mode a logical value. If TRUE (the default), then destination file(s) are given the same file mode as the sources.
copy.date a logical value. If TRUE, then destination file(s) are given the same file modification date as the sources. By default, FALSE.
path a character vector giving a single path name.
paths a character vector giving any number of path names.
mode a character vector. Sets the access limits on a directory or file.

Details

file.create creates files with the specified names. If the file already exists, it is truncated to length zero.
file.exists returns a logical vector the length of the combined arguments that is TRUE for each file that exists. For any file that does not exist, FALSE. This function can be applied to a folder.
dir.exists(paths) returns a logical vector the length of its paths argument. This vector contains TRUE for each path that exists and is a directory (folder). Otherwise, it contains FALSE.
file.remove removes the specified files.
file.rename renames the specified files given for from to the names given for to. This function can be applied on a folder.
file.append appends the contents of the files given for file2 to the files given for file1.
file.copy copies the files given for from to the names given for to. The to argument can specify a single existing directory.
file.symlink creates symbolic links on Unix-like platforms, which are not supported on the Windows platform. The specified to can be a file name or an existing directory.
file.link creates links on Unix-like platforms or hard links on Windows NTFS platform.
dir.create creates the single directory, unless recursive is TRUE, in which case all necessary directories specified for path are created. If the specified path exists, and showWarnings is TRUE, a warning message is displayed.
Sys.readlink for each character string in paths, return one of the following:
- If the string specifies a symbolic link, then return the name of the file linked to.
- If the string specifies an ordinary file or directory, then return an empty string.
- If the string specifies a nonexistent file or directory, then return NA.
Symbolic links are not supported on Windows. In that case, this function returns an empty string for each input string.
Value
returns a logical vector the length of the combined arguments. TRUE indicates a successful operation for that element.
Side Effects
Files or directories are created, removed, copied, or appended to.
See Also
file.access, file.show, basename, unlink.
Examples
tfile1 <- tempfile("a")
tfile2 <- tempfile("b")
tfile3 <- tempfile("c")
cat("This is file 1\n", file=tfile1)
cat("This is file 2\n", file=tfile2)
file.append(tfile1, tfile2)
file.copy(tfile1, tfile3)
file.remove(tfile1)

file.exists(tfile1) tdir <- tempfile("d") dir.create(tdir) file.copy(c(tfile2, tfile3), tdir) list.files(tdir)

file.create(file.path(tdir, c("tfile4", "tfile5"))) file.rename(file.path(tdir, c("tfile4", "tfile5")), file.path(tdir, c("tfile6", "tfile7"))) list.files(tdir)

# Clean up: unlink(c(tfile1, tfile2, tfile3, tdir))

Package base version 6.1.1-7
Package Index