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,
If you want to copy files that lie inside one folder so that they lie inside of a second folder e.g.
dir1/file1.txt
dir1/nested/file2.txt
to:
dir2/file1.txt
dir2/nested/file2.txt
Then this code works:
from <- "dir1"
to <- "dir2"
file.copy(list.files(from, full.names = TRUE),
to,
recursive = TRUE)
Avoid using recursive=TRUE
in the list.files()
command otherwise you lose the nesting.
file.copy(list.files(from, full.names = TRUE, recursive = TRUE),
to,
recursive = TRUE)
# incorrect
# dir2/file1.txt
# dir2/file2.txt
Other answers above didn't help with above scenario, eg:
file.copy(from, to, recursive=TRUE)
# incorrect - makes:
# dir2/dir1/file1.txt
# dir2/dir1/nested/file2.txt
file.copy('(...)/path_to_folder_Z', '(...)/folder_X')
# overwrites existing folder if in same parent directory