Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import simpledialog as spd
- from tkinter import messagebox as mb
- import os
- try:
- import shutil
- except ModuleNotFoundError:
- os.system('pip install shutil')
- import shutil
- _root = frame1
- topbar = tk.Frame(_root, bd=1, relief='solid', bg='white', height=30)
- dirframe = tk.Frame(_root, bd=0, bg='white')
- topbar.pack(fill='x')
- dirframe.pack(expand=True, fill='both')
- global CURRENT_PATH
- CURRENT_PATH = 'T:\\Storage'
- SYSTEM_DIRECTORIES = [
- r"T:\BIOS Programs",
- r"T:\TechOS",
- r"T:\ProgramData",
- r"T:\ProgramData\Info",
- r"T:\TechOS\Virtual",
- r"T:\TechOS\Virtual\Images",
- r"T:\TechOS\Virtual\Images\Wallpapers",
- r"T:\TechOS\Virtual\Info",
- r"T:\TechOS\Virtual\Settings",
- r"T:\TechOS\Virtual\Cursors"
- ]
- def goback():
- prvpath = os.path.dirname(CURRENT_PATH)
- global directory
- directory(prvpath)
- back = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', font='TkDefaultFont 20', width=30, height=30, command=goback)
- back.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Back.png')
- back.config(image=back.image)
- back.pack(side='left', anchor='w', fill='y')
- dirlabel = tk.Label(topbar, bg='white', text=CURRENT_PATH)
- dirlabel.pack(side='left', anchor='w', fill='y')
- def rename(path):
- global SYSTEM_DIRECTORIES
- global os
- global mb
- global spd
- global CURRENT_PATH
- if any(i in path for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Permission Denied", "You do not have permission to rename this file.")
- else:
- newfilename = spd.askstring("Rename file", "Rename \"" + os.path.basename(path) + "\":")
- if newfilename == None:
- pass
- else:
- path0 = os.path.dirname(path)
- try:
- os.rename(path, os.path.join(path0, newfilename))
- except:
- mb.showinfo("Error", "Could not rename file")
- directory(CURRENT_PATH)
- def delete(path):
- global SYSTEM_DIRECTORIES
- global os
- global mb
- global CURRENT_PATH
- global directory
- global shutil
- if any(i in path for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Permission Denied", "You do not have permission to delete this file.")
- else:
- if os.path.isfile(path):
- try:
- os.remove(path)
- except:
- mb.showinfo("Error", "Could not delete file")
- elif os.path.isdir(path):
- continuedelete = mb.askyesno("Delete Folder", "Are you sure you want to delete this folder and all its files?")
- if continuedelete == True:
- try:
- shutil.rmtree(path)
- except:
- mb.showinfo("Error", "Could not delete folder")
- else:
- pass
- directory(CURRENT_PATH)
- def newfile():
- global CURRENT_PATH
- global directory
- filepath1 = os.path.join(CURRENT_PATH, 'Untitled')
- rep = 0
- while True:
- if os.path.exists(filepath1 + str(rep) + '.txt'):
- rep += 1
- else:
- filepath0 = filepath1 + str(rep) + '.txt'
- break
- NEW_FILE = open(filepath0, 'x')
- NEW_FILE.close()
- directory(CURRENT_PATH)
- def newfolder():
- global CURRENT_PATH
- global directory
- folderpath1 = os.path.join(CURRENT_PATH, 'New Folder')
- if os.path.exists(folderpath1):
- rep = 1
- while True:
- if os.path.exists(folderpath1 + ' (' + str(rep) + ')'):
- rep += 1
- else:
- folderpath0 = folderpath1 + ' (' + str(rep) + ')'
- break
- os.mkdir(folderpath0)
- else:
- os.mkdir(folderpath1)
- directory(CURRENT_PATH)
- newfilebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='+ File ', command=newfile)
- newfilebutton.pack(side='right', anchor='e', fill='y')
- newfolderbutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='+ Folder', command=newfolder)
- newfolderbutton.pack(side='right', anchor='e', fill='y')
- def directory(path):
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- if any(path == i for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Careful!", "The directory you are about to enter contains system files. Modifying these files might cause irreparable damage to your system.")
- CURRENT_PATH = path
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: directory(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Folder.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, fullpath=fullpath: rename(fullpath))
- tempbutton.bind("<Button-2>", lambda event, fullpath=fullpath: delete(fullpath))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: openfile(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/File.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, fullpath=fullpath: rename(fullpath))
- tempbutton.bind("<Button-2>", lambda event, fullpath=fullpath: delete(fullpath))
- except NotADirectoryError:
- spd.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- def directory_rename():
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- global directory
- path = CURRENT_PATH
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: rename(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FolderRename.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: rename(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FileRename.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- except NotADirectoryError:
- spd.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- def directory_delete():
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- global directory
- path = CURRENT_PATH
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: delete(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FolderDelete.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: delete(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FileDelete.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- except NotADirectoryError:
- spd.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- deletebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='Delete', command=directory_delete)
- deletebutton.pack(side='right', anchor='e', fill='y')
- renamebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='Rename', command=directory_rename)
- renamebutton.pack(side='right', anchor='e', fill='y')
- dirframe.bind("<Button>", lambda event, cp=CURRENT_PATH: directory(cp))
- directory(CURRENT_PATH)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement