Home > Net >  Copying over files from multiple directories into one folder
Copying over files from multiple directories into one folder

Time:01-30

I'm looking to copy a set of files from multiple directories into one new folder using this code:

file.copy(from = paste0('directory1', all_files),
          to = paste0('directory2', all_files))

all_files is a character vector of files including their full path location. I've also tried using basename(all_files) with no luck.

I've tried using the code above

CodePudding user response:

Just following up - I've figured it out.

It wasn't working because the paste was redundant, this code fixed it:

for (n in 1:length(all_files)) {
  file.copy(from = all_files[n],
           to = 'directory2')
}

CodePudding user response:

I think you need to use the below code, in the to argument we need to use the new folder path where the files need to the copied over

file.copy(from = paste0('directory1', all_files),
          to = directory2)
  •  Tags:  
  • r
  • Related