Copying list of files from one folder to other in R

前端 未结 2 952
暗喜
暗喜 2020-12-17 15:42

I am trying to bulk move files of different kinds in R.

origindir <- c(\"c:/origindir\")
targetdir <- c(\"c/targetdir\")
filestocopy <- c(\"myfile.         


        
相关标签:
2条回答
  • 2020-12-17 16:20

    As Joran and Chase have already pointed out in the comments, all you need to do is:

    file.copy(from=filestocopy, to=targetdir, 
              overwrite = recursive, recursive = FALSE, 
              copy.mode = TRUE)
    

    Then, if you're actually moving the files, remove the originals with:

    file.remove(filestocopy)
    
    0 讨论(0)
  • 2020-12-17 16:23

    Just expanding Chase's suggestion.

    lapply(filestocopy, function(x) file.copy(paste (origindir, x , sep = "/"),  
              paste (targetdir,x, sep = "/"), recursive = FALSE,  copy.mode = TRUE))
    
    0 讨论(0)
提交回复
热议问题