Code: Alles auswählen
import os, sys, string, shutil
from __builtin__ import file
from Tkinter import *
from tkFileDialog import *
count = 0
def lesen(weg, h1, h2, h3, h4, h5, h6, h7):
# liest den Paht rekursiv aus(count ist stopper fals zu viele Unterordner)
global count
count = count + 1
if count <=1:
p = os.listdir(weg)
checklist(p, weg, h1, h2, h3, h4, h5, h6, h7)
count = count -1
else:
print "weiter nicht\n"
def checklist(p, weg, h1, h2, h3, h4, h5, h6, h7):
#überprüft ob datei oder verzeichnis, splittet datei name auf
for i in p:
i = i.strip()
print i
if os.path.isdir(weg+ "\\" +i):
print "ist dir"
lesen(weg+ "\\" +i, h1, h2, h3, h4, h5, h6, h7)
else:
print "ist datei"
s = string.split(i, '.')
t = s[-1]
erkenn(t, i, weg, h1, h2, h3, h4, h5, h6, h7)
def erkenn(t, i, weg, h1, h2, h3, h4, h5, h6, h7):
#überprüft ob Datei schon im neuen Verzeichnis existiert
g = (weg+ "\\" +i)
u1 = (h1+ "\\" +i)
u2 = (h2+ "\\" +i)
u3 = (h3+ "\\" +i)
u4 = (h4+ "\\" +i)
u5 = (h5+ "\\" +i)
u6 = (h6+ "\\" +i)
u7 = (h7+ "\\" +i)
if os.path.exists(u1):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u2):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u3):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u4):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u5):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u6):
print "File existiert bereits"
dr = i
drin(dr)
elif os.path.exists(u7):
print "File existiert bereits"
dr = i
drin(dr)
else:
schieb(g,t,i,weg,u1,u2,u3,u4,u5,u6,u7)
def drin(dr): #bricht ab und kehrt zu lesen zurück
del dr
def schieb(g, t, i, weg, u1, u2, u3, u4, u5, u6, u7):
#ordnet anhand der endung
Bilder=['bmp','gif','GIF','jpeg','JPEG','JPG','jpe','JPE','jpg', 'paint',\
'psp','PSP','giff','cvs']
Text=['txt','doc','tif', 'tiff', 'pdf','rtf','cad',\
'dcd','fm','ftp','lwd','msw','wks','csv']
Prog=['py', 'pyc', 'exe','dll','cab','asp','zip','tgz','bat','inf','com','dcr']
Flash=['fla','swf','jcd','rf','jc', 'sbl','jc!']
Mov=['asf','mpg','mpeg','avi','divx','mov','mp','mpe','mmm','mmp',\
'mp','mvi','ptv','qtvr','pt','qtm','swf','awa','awm','mswmm','tgp','swi',\
'cmr','dir','dxr','scm','spl','xmz']
audio=['mp3','MP3','aif','cda','msv','nra','ra','ram','wav','bun','esf','gsd',\
'hit','la','lam','lma','m1a','mus','ra','ram','rm','rmm','rnx']
html=['htm','html','HTM','HTML','xml','XML','dhtml', 'xhtml']
if t in Text:
os.rename(g, u1)
print "fertig\n"
elif t in Prog:
os.rename(g, u2)
print "fertig\n"
elif t in Bilder:
os.rename(g, u3)
print "fertig\n"
elif t in Flash:
os.rename(g, u4)
print "fertig\n"
elif t in Mov:
os.rename(g, u5)
print "fertig\n"
elif t in html:
os.rename(g,u6)
print "fertig\n"
elif t in audio:
os.rename(g,u7)
print "fertig\n"
else:
print "Konnte nicht zugeordnet werden"
def main(): #weg abfrage
weg = (r'H:\Python\Probe\naja')
#raw_input('Path eingabe:')
h1 =(r'H:\Python\Probe\ausgabe\Text')
#raw_input('Speicherort fuer\n Textdateien:')
if not os.path.isdir(h1):
os.mkdir(h1 )
h2 =(r'H:\Python\Probe\ausgabe\Prog')
#raw_input('Speichertort\n für Programme:')
if not os.path.isdir(h2):
os.mkdir(h2 )
h3 =(r'H:\Python\Probe\ausgabe\bilder')
#raw_input('Speichertort\n für Bilder:')
if not os.path.isdir(h3):
os.mkdir(h3 )
h4 =(r'H:\Python\Probe\ausgabe\fla')
#raw_input('Speichertort\n für flash:')
if not os.path.isdir(h4):
os.mkdir(h4 )
h5 =(r'H:\Python\Probe\ausgabe\movie')
#raw_input('Speichertort\n für movies:')
if not os.path.isdir(h5):
os.mkdir(h5 )
h6 =(r'H:\Python\Probe\ausgabe\html')
#raw_input('Speicherort\n für Internetseiten:')
if not os.path.isdir(h6):
os.mkdir(h6 )
h7 =(r'H:\Python\Probe\ausgabe\audio')
#raw_input('Speicherort\n für audiodateien:')
if not os.path.isdir(h7):
os.mkdir(h7 )
lesen(weg, h1, h2, h3, h4, h5, h6, h7)
def later():
print 'noch in arbeit'
def oeffnen():
answer = askopenfilename()
print answer #noch in arbeit
def speichern():
ans = asksaveasfilename()
print ans #noch in arbeit
#Hauptprogramm
root = Tk()
menu=Menu(root)
root.config(menu=menu)
filemenu=Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='Öffnen', command=oeffnen)
filemenu.add_command(label='Speichern', command=speichern)
filemenu.add_separator()
filemenu.add_command(label='Beenden', command=root.destroy)
helpmenu=Menu(menu)
menu.add_cascade(label="Hilfe", menu=helpmenu)
helpmenu.add_command(label='About', command=later)
toolbar = Frame(root)
Box = toolbar
Box.pack(side=BOTTOM)
# die eigentliche Listbox
fenster = Listbox(Box, width=30, bg = "black", fg = "green", selectmode=SINGLE)
fenster.pack(side=TOP)
b = Button(toolbar,text="start", width=8, command=main)
b.pack(side=LEFT,padx=2,pady=2)
b = Button(toolbar,text="Beenden", width=8, command=root.destroy)
b.pack(side=LEFT,padx=2,pady=2)
toolbar.pack(side=TOP)
mainloop()