Home > database >  How move files based on file names in R?
How move files based on file names in R?

Time:05-15

I know the question was asked many times but still i'm copying empty file. let's assume i have 50000k files and i have around 3000 file names as a vector so i want to move the files to different folder based on their names.

for (i in files) {
  for (j in files_names) {
    if ( i == j){
      
          file_copy(i, "C:/copy/to_this_folder")

    }
  }
}

But it moves the files but all of them were 0KB. Can any one please explain this to me

CodePudding user response:

Does this work for you?

letters
x = c("a", "b", "c", "2")
for (name in x[x %in% letters]) {
  file.copy(name, "tmp/")
}

Also, remember to use getwd() to check whether your working directory is correct or not.

  • Related