[英]how do I copy over a few folders from one directory into another folder in Linux using python
I'm trying to copy over a bunch of folders, read from a txt file into another folder.我正在尝试复制一堆文件夹,从一个 txt 文件读取到另一个文件夹中。 How do I do this?
我该怎么做呢? I'm using python in Linux
我在 Linux 中使用 python
eg this txt file has the following folder names例如,此 txt 文件具有以下文件夹名称
001YG
00HFP
00MFE
00N38
00NN7
00SL4
00T1E
00T4B
00X3U
00YZL
00ZCA
01K8X
01KM1
01KML
01O27
01THT
01ZWG
and I want to copy these folders and their contents to a folder called duplicate-folder
我想将这些文件夹及其内容复制到一个名为
duplicate-folder
How do I do this?我该怎么做呢? I tried the following code but it gave an error because I think it's only for files, not folders:)
我尝试了以下代码,但它给出了一个错误,因为我认为它只适用于文件,而不适用于文件夹:)
with open("missing-list-files.txt",'w') as outfile:
# outfile.write('\n'.join(temp3))
for x in temp3:
outfile.write(x + '\n')
filelistset = temp3
dest = 'mydirectoryhere'
for file in filelistset:
shutil.copyfile(file ,dest + file)
use shutil.copytree(src, dest, ...)
( https://docs.python.org/3/library/shutil.html#shutil.copytree ) for directories (also copies subfiles and -directories. And also don't forget to give it the full path for file and dest (don't know which value your temp3 var holds). If you don't give it a full path, but only a filename, it will search in the current working directory.将
shutil.copytree(src, dest, ...)
( https://docs.python.org/3/library/shutil.html#shutil.copytree ) 用于目录(也复制子文件和目录。也不要'不要忘记给它提供文件和目标的完整路径(不知道你的 temp3 变量持有哪个值)。如果你不给它一个完整路径,而只给它一个文件名,它将在当前工作目录中搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.