# -*- coding: utf-8 -*-

import time, tkinter, sys, tkinter.scrolledtext, os, shutil, random
from tkinter import PhotoImage
from tkinter import END
from tkinter import messagebox
from tkinter import Radiobutton
from tkinter import filedialog


def suchen():
    global suchenv
    suchenv = tkinter.filedialog.askdirectory()
    suche["text"] = suchenv

 
def add_at_position():
        
    liste = os.listdir(suchenv)
    tex = text.get(0.0, tkinter.END).replace("\n", "")
    ii = 0   
    print(str(liste[ii]))
    print(str(suchenv))
 
    for i in liste:
    
        if i.find(".") != -1:
            listesplit = liste[ii].split(".")
            listesplit2 = listesplit[0][0:500]
            print(listesplit2)
            os.rename(suchenv + "/" + liste[ii], suchenv + "/" + listesplit[0] + "." + tex)
            ii = ii+1
                
        else:
                
            ii = ii+1
            
        lbl_prozess["text"] = "File " + str(ii) + " of " + str(len(liste)) + " renamed."

            
main = tkinter.Tk()
main.maxsize()

fr = tkinter.Frame(main, width = 1024, bd=40, bg="#ffffff")
fr.pack()

#Daten fÃƒÂ¼r GUI zusammenstellen

suche = tkinter.Button(fr, text = "Search folder", bg="#ffffff", width = 36, command = suchen)
lbl_leer = tkinter.Label(fr, text = "", bg="#ffffff")
lbl_leer2 = tkinter.Label(fr, text = "", bg="#ffffff")
text = tkinter.Text(fr, width = 32, height = 1, bg="#ffffff")
lbl_prozess = tkinter.Label(fr, text = "", bg="#ffffff")
actionbutton4 = tkinter.Button(fr, text = "Add at Position", width="35", command = add_at_position, bg="#ffffff")

#Befehl fÃƒÂ¼r Ausgabe

suche.grid(row = 1, column=1, columnspan = 2, sticky ="w")
lbl_leer.grid(row = 2, column=1, columnspan = 2, sticky ="w")
text.grid(row = 3, column=1, columnspan = 2, sticky ="w")
lbl_leer2.grid(row = 5, column=1, columnspan = 2, sticky ="w")
lbl_prozess.grid(row = 6, column=1, columnspan = 2, sticky ="w")
actionbutton4.grid(row = 10, column=1, columnspan = 2, sticky ="w")

main.mainloop()
