我正在尝试将过去24小时内修改或创建的任何文本文件从一个文件传输到另一个文件。到目前为止,GUI允许用户选择源文件和目标文件,并且在运行时,不会发生错误,也不会移动任何文件。有没有我没看到的东西?
import shutil
import os
import time
from tkinter import *
import tkinter.filedialog as fdialog
class MainClass():
def __init__(self, master):
self.parent=master
self.gui()
def gui(self):
self.Source=StringVar()
self.Destination=StringVar()
MySource=Entry(myGUI, textvariable=self.Source).grid(row=9, column=2)
browse1=Button(myGUI, text="Browse",command=lambda:self.Source.set(fdialog.askdirectory())).grid(row=9, column=3)
MyDestination=Entry(myGUI, textvariable=self.Destination).grid(row=10, column=2)
browse2=Button(myGUI,text="Browse",command=lambda:self.Destination.set(fdialog.askdirectory())).grid(row=10, column=3)
buttonCopy=Button(myGUI, text=" Copy ", command=self.copyy).grid(row=11, column=3)
SECONDS_IN_DAY = 24 * 60 * 60
now = time.time()
before = now - SECONDS_IN_DAY
def last_mod_time(fname):
return os.path.getmtime(fname)
def copyy(self):
source_file=self.Source.get()
if (source_file.endswith(".txt") and last_mod_time(src_fname) > before):
shutil.copy(source_file, self.Destination.get())
if __name__ == '__main__':
myGUI=Tk()
app=MainClass(myGUI)
myGUI.geometry("400x200+100+200")
myGUI.mainloop()