小编Jas*_*nDL的帖子

Python-将特定文件从列表复制到新文件夹中

我试图让我的程序从文件(例如 .txt)中读取名称列表,然后在选定的文件夹中搜索这些文件,并将这些文件复制并粘贴到另一个选定的文件夹中。我的程序运行没有错误,但没有执行任何操作:

代码 - 更新:

import os, shutil
from tkinter import filedialog
from tkinter import *


root = Tk()
root.withdraw()

filePath = filedialog.askopenfilename()
folderPath = filedialog.askdirectory()
destination = filedialog.askdirectory()

filesToFind = []
with open(filePath, "r") as fh:
    for row in fh:
        filesToFind.append(row.strip())

#Added the print statements below to check that things were feeding correctly
print(filesToFind)
print(folderPath)
print(destination)

#The issue seems to be with the copy loop below:    
for target in folderPath:
    if target in filesToFind:
        name = os.path.join(folderPath,target)
        print(name)
        if …
Run Code Online (Sandbox Code Playgroud)

python copy-paste tkinter shutil python-3.x

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

copy-paste ×1

python ×1

python-3.x ×1

shutil ×1

tkinter ×1