Am I missing something in the functions?
I want to copy a folder with some files and another subfolder from one location to another. I tried to use file.copy(from, to,
Here is another possibility :
create_Directory <- function(source_Directory = "C:/dir1",
target_Directory = "C:/dir2")
{
setwd(source_Directory)
list_Dirs <- list.dirs()
setwd(target_Directory)
bool_Dir_Exists <- dir.exists(list_Dirs)
dirs_To_Create <- list_Dirs[!bool_Dir_Exists]
for(dir in dirs_To_Create)
{
dir.create(dir)
}
}
copy_Content_From_One_Directory_To_Another <- function(source_Directory = "C:/dir1",
target_Directory = "C:/dir2")
{
#### Create the sub directories ####
create_Directory(source_Directory = source_Directory,
target_Directory = target_Directory)
#### Copy the files ####
setwd(source_Directory)
list_Files <- list.files(recursive = TRUE, full.names = TRUE)
list_Files <- gsub(pattern = paste0("(\\.)",.Platform$file.sep), replacement = "", list_Files)
file.copy(from = paste0(source_Directory, .Platform$file.sep
, list_Files),
to = paste0(target_Directory, .Platform$file.sep , list_Files))
}
copy_Content_From_One_Directory_To_Another()