在R中将文件列表从一个文件夹复制到另一个文件夹 [英] Copying list of files from one folder to other in R
本文介绍了在R中将文件列表从一个文件夹复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 R 中批量移动不同类型的文件.
I am trying to bulk move files of different kinds in R.
origindir <- c("c:/origindir")
targetdir <- c("c/targetdir")
filestocopy <- c("myfile.doc", "myfile.rda", "myfile.xls",
"myfile.txt", "myfile.pdf", "myfile.R")
我尝试了以下操作,但不知道如何处理所有文件:
I tried the following, but do not know how to do for all files:
file.copy(paste (origindir, "myfile.doc", sep = "/"),
paste (targetdir, "myfile.doc", sep = "/"),
overwrite = recursive, recursive = FALSE,
copy.mode = TRUE)
我不知道该怎么做.
推荐答案
正如 Joran 和 Chase 在评论中已经指出的那样,您需要做的就是:
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)
这篇关于在R中将文件列表从一个文件夹复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文