Moving files between folders

If you wanted a file.rename()-like function that would also create any directories needed to carry out the rename, you could try something like this:

my.file.rename <- function(from, to) {
    todir <- dirname(to)
    if (!isTRUE(file.info(todir)$isdir)) dir.create(todir, recursive=TRUE)
    file.rename(from = from,  to = to)
}

my.file.rename(from = "C:/Users/msc2/Desktop/rabata.txt",
               to = "C:/Users/msc2/Desktop/Halwa/BADMASHI/SCOP/rabata.txt")

Leave a Comment