Code: Alles auswählen
from Tkinter import *
import sys
import tkFileDialog
import tkSimpleDialog
import os,time
FolderToScan = None
EmailAdress = None
def ChangeFolder():
FolderToScan = tkFileDialog.askdirectory()
def EmailAdress():
Subwindow1 = Tk()
Subwindow1.geometry("200x100+0+0")
Label1= Label(Subwindow1, text = "E-Mailadress :")
Label1.place(x = 5, y = 10)
EmailAdress = Entry(Subwindow1, width=30)
EmailAdress.place(x = 5, y = 35)
Subwindow1.mainloop()
def ChangeLogFolder():
FolderToSaveLog = tkFileDialog.askdirectory()
def watch_directories (paths , func, delay = 1.0):
all_files = {}
def f (unused, dirname, files):
for filename in files:
path = os.path.join(dirname, filename)
try:
t = os.stat(path)
except os.error:
continue
mtime = remaining_files.get(path)
if mtime is not None:
del remaining_files[path]
if t.st_mtime > mtime:
changed_list.append(path)
else:
changed_list.append(path)
all_files[path] = t.st_mtime
rescan = False
while true:
changed_list = []
remaining_files = all_files.copy()
all_files = {}
for path in paths:
os.path.walk(path, f, None)
removed_list = remaining_files.keys()
if rescan:
rescan = False
elif changed_list or removed_list:
rescan = func(changed_list, removed_list)
time.sleep(delay)
if _name_ == '_main_':
def f (changed_files, removed_files):
print changed_files
print 'Removed', removed_files
watch_directories([FolderToScan], f, 1)
Mainwindow = Tk()
Mainwindow.geometry("400x200+0+0")
#Logo = PhotoImage(file ="I:\Groups3\ELE HW\SYSTEMS_BENCH\PRAK\Patrick Waibel\Projekte\Projekt Folder Scanner\logo.jpg")
#Label2 = Label(image = Logo).pack()
RunScriptButton = Button(Mainwindow, text = "Run script", bg = "green", width = 25, height = 2, command = watch_directories)
RunScriptButton.place(x = 25, y = 30)
StopScriptButton = Button(Mainwindow, text = "Stop script",bg = "red", width = 25, height = 2, command = sys.exit)
StopScriptButton.place(x = 215, y = 30)
ChangeFolderButton = Button(Mainwindow, text = "Change folder to scan", width = 25, command = ChangeFolder)
ChangeFolderButton.place(x = 25, y = 100)
ChangeMailAdressButton = Button(Mainwindow, text = "Change mailadress", width = 25, command = EmailAdress)
ChangeMailAdressButton.place(x = 215, y = 100)
ChangeLogButton = Button(Mainwindow, text = "Change destination of logfile", width = 25, command = ChangeLogFolder)
ChangeLogButton.place(x = 25, y = 150)
del FolderToScan
mainloop()
Psus82
Edit (Leonidas): Code in Python-Tags gesetzt.