renameFiles: rename files

View source: R/renameFiles.R

renameFilesR Documentation

rename files

Description

rename files

Usage

renameFiles(old, new, replacement = "_", checkExtention = TRUE)

Arguments

old

the original file names. The path information IS allowed,

new

the new file names. Unless on purpose, the path information should NOT be included, because "/" in the new file names will be replaced by characters according to replacement parameter, and the files are saved in the same folder(s) as the old files.

replacement

character(s) to replace the illegal characters in the new names.

checkExtention

logical, if TRUE (default) check if new names contains a file extension.

Examples

# old file names
tmpFolder = "./tmp"
dir.create(tmpFolder)
file1 = tempfile(pattern = "oldFile", tmpdir = tmpFolder, fileext = ".csv")
file2 = tempfile(pattern = "oldFile", tmpdir = tmpFolder, fileext = ".csv")
write.csv(cars, file = file1)
write.csv(cars, file = file2)
dir(tmpFolder)

# new file names (must not contain the path, i.e. "./tmp/"!)
newNames = sub("./tmp/oldFile", "newFile", c(file1, file2))
renamed = renameFiles(old = c(file1, file2), new = newNames)
renamed

dir(tmpFolder)

paodan/funcTools documentation built on April 1, 2024, 12:01 a.m.