将文件列表从一个文件夹复制到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屋!
查看全文