从子目录中复制许多文件

copy many files from subdirectories

我正在尝试将多个子目录中的文件 copy/move 放入一个文件夹中:

new.folder <- "path/to/new/folder"
files <- basename(list.files(path, recursive = T))
file.copy(from=files, to=new.folder)

不幸的是,我收到了所有文件的错误:

In file.copy(from = files, to = new.folder):
  problem copying ./E202.fastq.gz to /path/to/new/folder/E202.fastq.gz: No such file or directory

我很感激任何帮助,我是 R 的新手。

确保所有文件都存在:

all(file.exists(files))

否则,使用full.names = TRUE

files <- list.files(path, recursive = TRUE, full.names = TRUE)

因为如果你不这样做,文件将被假定在当前目录中

getwd()

可能等于也可能不等于path