我想从一个位置复制一个目录到其他位置,我已经为此编写了代码。执行IDE会给我一个例外。在Python中复制目录
import sys
import os
from Tkinter import *
from tkCommonDialog import Dialog
import shutil
import tkFileDialog
import win32com.client
win = Tk()
win.title("Copying the Dorectory to specified location")
win.geometry("600x600+200+50")
win.resizable()
class Copy:
def __init__(self,Obj):
la = Label(win, text = "Source Directory is",font = "verdana 12 italic bold", width = 20,fg = "Red", bg = "WHITE",)
la.grid(row=1, column =1)
abc = "tk_chooseDirectory"
bu = Button(text="Source", font = "Verdana 12 italic", command= abc)
bu.grid(row =1 , column =3)
la1 = Label(win, text = "DestibationDirectory is",font = "verdana 12 italic bold", width = 20,fg = "Red", bg = "WHITE",)
la1.grid(row=2, column =1)
abc1 = "tk_chooseDirectory"
bu1 = Button(text="Destination", font = "Verdana 12 italic", command=abc1)
bu1.grid(row =2 , column =3)
def start():
shutil.copy(abc, abc1)
bu2 = Button(text="Copy", font= "Verdana 12 bold", command =start)
bu2.grid(row =3, column =2)
obj = Copy(win)
win.mainloop()
这是我的代码和我对着异常
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Documents and Settings\Bharath Gupta\Desktop\task.py", line 38, in start
shutil.copy(abc, abc1)
File "C:\Python27\lib\shutil.py", line 116, in copy
copyfile(src, dst)
File "C:\Python27\lib\shutil.py", line 68, in copyfile
raise Error("`%s` and `%s` are the same file" % (src, dst))
Error: `tk_chooseDirectory` and `tk_chooseDirectory` are the same file
请有人帮我摆脱了异常。
使用'shutil.copytree'复制整个目录。 – 2011-12-20 07:10:36
朋友最后我得到了答案给我的Quesn ;;;这很简单,我们应该调用类名称规范的变量,如“”“classname.variablename”“” – 2011-12-21 09:57:56