我正在尝试从一个文件夹中读取多个图像并将其复制到另一个文件夹。我可以选择多张图像,但是当我按下“文件打开”按钮时,会发生上述错误
@udf
...your code...
答案 0 :(得分:0)
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 16:19:47 2020
@author: tkumar
"""
"""
This block of code moves images from one folder(source) to another (destination))
"""
import shutil,os,glob
from tkinter import filedialog
from tkinter import *
from tkinter.filedialog import askopenfilenames
from tkinter.filedialog import askdirectory
def callback():
#src =''
tup= askdirectory()
src= filedialog.askdirectory()
# src =" ".join(tup)
print("------------",type(src))
#des=''
des= r"C:\Users\tkumar\.spyder-py3\there"
sourceFiles = os.listdir(src)
#print(len(sourceFiles))
#shutil.copy(src, des)
try:
for fileName in sourceFiles:
fullName = os.path.join(src, fileName)
if (os.path.isfile(fullName)):
shutil.copy(fullName, des)
except Exception as e:
print("Error %s" %e)
errmsg = 'Error!'
Button(text='File Open', command=callback).pack(fill=X)
mainloop() ```