将文件列表从一个文件夹复制到R中的其他文件夹

jon*_*jon 14 directory r copy-paste

我试图在R中批量移动不同种类的文件

origindir <- c("c:/origindir")
targetdir <- c("c/targetdir")
filestocopy <- c("myfile.doc", "myfile.rda", "myfile.xls", 
                 "myfile.txt", "myfile.pdf", "myfile.R")
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法,但不知道如何处理所有文件:

file.copy(paste (origindir, "myfile.doc", sep = "/"), 
          paste (targetdir, "myfile.doc", sep = "/"), 
          overwrite = recursive, recursive = FALSE, 
          copy.mode = TRUE)
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做.

A5C*_*2T1 16

正如Joran和Chase已经在评论中指出的那样,你需要做的就是:

file.copy(from=filestocopy, to=targetdir, 
          overwrite = recursive, recursive = FALSE, 
          copy.mode = TRUE)
Run Code Online (Sandbox Code Playgroud)

然后,如果您实际上正在移动文件,请删除原件:

file.remove(filestocopy)
Run Code Online (Sandbox Code Playgroud)

  • 我收到此消息:`文件中的错误(从 = 文件复制,到 = targetdir,覆盖 = 递归,:未找到对象“递归”`。递归不是内置函数吗? (3认同)