根据存储在.txt文件中的列表复制文件 [英] Copy files based on a list stored in .txt file

查看:381
本文介绍了根据存储在.txt文件中的列表复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源文件夹 目标文件夹 我要从源文件夹复制到目标文件夹的文件列表,该文件已保存到.txt文件

I have a source folder Destination folder List of files I want to be copied from source folder to destination folder, which has been saved to a .txt file

listtocopy.txt如下-不确定它是否重要,但它们是Anabat ZC文件.

listtocopy.txt is as below - not sure if it's important but they are Anabat ZC files.

S5281925.35#
S5282317.26#
S5290100.39#
S5281859.28#
S5281932.18#
S5290420.20#

我不想复制所有文件.

我是R的新手-到目前为止,这是我所拥有的-但它不起作用.我认为它无法将列表识别为文件名的列表".

I'm new to R -this is what I have so far - but it's not working. I think it's not recognizing the list as a 'list' of file names.

# Copy based on list
# identify the folders
current.folder <- "H:/Documents/1_PhD_Network/Auto_ID/Anabat7_11"
new.folder <- "H:/Documents/1_PhD_Network/Auto_ID/Scan_outputs"

#read listtocopy and assign to list
list<-read.delim("H:/Documents/1_PhD_Network/Auto_ID/Scan_outputs/listtocopy.txt")

# copy the files to the new folder
file.copy(list, new.folder)

推荐答案

我认为文本文件的读取方式存在问题? 无论如何,这行得通.感谢所有回答.

I think there was a problem with how the text file was being read?? anyway, this works. thanks to all that answered.

# identify the folders
current.folder <- "C:/Users/Amanda/Desktop/testcopy/Anabat7_11"
new.folder <- "C:/Users/Amanda/Desktop/testcopy/Scan_outputs"

# find the files that you want
list_of_files <- read.delim("listtocopy.txt",header = F) 

#check
print(list_of_files)

#copy vector
setwd(current.folder) 
for(i in list_of_files)
{
  file.copy(i, new.folder)
}

这篇关于根据存储在.txt文件中的列表复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆