如何在R中将文件从一个文件夹移动到另一个文件夹?

如何在R中将文件从一个文件夹移动到另一个文件夹?,r,R,我知道以前有人问过这个问题,但除了使用file.rename()函数外,还有一点变化 我创建了一个变量,它使用setdiff函数来比较文件夹1中有哪些文件和文件夹2中没有的文件。根据文件名,文件夹1中约有100个文件夹2没有的文件。我想把这100个文件移到文件夹3中 我该怎么做呢 我会使用if-then语句吗?假设您有一个要复制的名称列表,并且目标文件夹已经存在: # vector with the 100 files names to be copied names <- c("text

我知道以前有人问过这个问题,但除了使用file.rename()函数外,还有一点变化

我创建了一个变量,它使用setdiff函数来比较文件夹1中有哪些文件和文件夹2中没有的文件。根据文件名,文件夹1中约有100个文件夹2没有的文件。我想把这100个文件移到文件夹3中

我该怎么做呢


我会使用if-then语句吗?

假设您有一个要复制的名称列表,并且目标文件夹已经存在:

# vector with the 100 files names to be copied
names <- c("text1.txt", "text2.txt") 

# custom function
my_function <- function(x){
  file.rename( from = file.path("yourpath/folder1", x) ,
               to = file.path("yourpath/folder3", x) )
}

# apply the function to all files
lapply(names, my_function)
#包含要复制的100个文件名的向量

名称假设您有要复制的名称列表,且目标文件夹已存在:

# vector with the 100 files names to be copied
names <- c("text1.txt", "text2.txt") 

# custom function
my_function <- function(x){
  file.rename( from = file.path("yourpath/folder1", x) ,
               to = file.path("yourpath/folder3", x) )
}

# apply the function to all files
lapply(names, my_function)
#包含要复制的100个文件名的向量
名字