-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgfm.py
More file actions
82 lines (82 loc) · 4.3 KB
/
gfm.py
File metadata and controls
82 lines (82 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from tkinter import *
import tkinter.filedialog as fd
import tkinter.messagebox as mb
import os
import shutil
def open_file():
file = fd.askopenfilename(title='Choose a file of any type', filetypes=[("All files", "*.*")])
os.startfile(os.path.abspath(file))
def copy_file():
file_to_copy = fd.askopenfilename(title='Choose a file to copy', filetypes=[("All files", "*.*")])
dir_to_copy_to = fd.askdirectory(title="In which folder to copy to?")
try:
shutil.copy(file_to_copy, dir_to_copy_to)
mb.showinfo(title='File copied!', message='Your desired file has been copied to your desired location')
except:
mb.showerror(title='Error!', message='We were unable to copy your file to the desired location. Please try again')
def delete_file():
file = fd.askopenfilename(title='Choose a file to delete', filetypes=[("All files", "*.*")])
os.remove(os.path.abspath(file))
mb.showinfo(title='File deleted', message='Your desired file has been deleted')
def rename_file():
file = fd.askopenfilename(title='Choose a file to rename', filetypes=[("All files", "*.*")])
rename_wn = Toplevel(root)
rename_wn.title("Rename the file to")
rename_wn.geometry("250x70"); rename_wn.resizable(0, 0)
Label(rename_wn, text='What should be the new name of the file?', font=("Microsoft Sans Serif", 12)).place(x=0, y=0)
new_name = Entry(rename_wn, width=40, font=("Tahoma", 10))
new_name.place(x=0, y=30)
new_file_name = os.path.join(os.path.dirname(file), new_name.get()+os.path.splitext(file)[1])
os.rename(file, new_file_name)
mb.showinfo(title="File Renamed", message='Your desired file has been renamed')
def open_folder():
folder = fd.askdirectory(title="Select Folder to open")
os.startfile(folder)
def delete_folder():
folder_to_delete = fd.askdirectory(title='Choose a folder to delete')
os.rmdir(folder_to_delete)
mb.showinfo("Folder Deleted", "Your desired folder has been deleted")
def move_folder():
folder_to_move = fd.askdirectory(title='Select the folder you want to move')
mb.showinfo(message='You just selected the folder to move, now please select the desired destination where you want to move the folder to')
destination = fd.askdirectory(title='Where to move the folder to')
try:
shutil.move(folder_to_move, destination)
mb.showinfo("Folder moved", 'Your desired folder has been moved to the location you wanted')
except:
mb.showerror('Error', 'We could not move your folder. Please make sure that the destination exists')
def list_files_in_folder():
i = 0
folder = fd.askdirectory(title='Select the folder whose files you want to list')
files = os.listdir(os.path.abspath(folder))
list_files_wn = Toplevel(root)
list_files_wn.title(f'Files in {folder}')
list_files_wn.geometry('250x250')
list_files_wn.resizable(0, 0)
listbox = Listbox(list_files_wn, font=("Tahoma", 10))
listbox.place(relx=0, rely=0, relheight=1, relwidth=1)
scrollbar = Scrollbar(listbox, orient=VERTICAL, command=listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scrollbar.set)
while i < len(files):
listbox.insert(END, files[i])
i += 1
title = 'File Manager'
button_font = ("Tahoma", 10)
root = Tk()
root.title(title)
root.geometry('205x380')
root.resizable(0, 0)
root.config()
Label(root, text=title, font=("Microsoft Sans Serif", 12), wraplength=250).place(x=58, y=10)
Button(root, text='Open a file', width=20, font=button_font, command=open_file).place(x=30, y=50)
Button(root, text='Copy a file', width=20, font=button_font, command=copy_file).place(x=30, y=90)
Button(root, text='Rename a file', width=20, font=button_font, command=rename_file).place(x=30, y=130)
Button(root, text='Delete a file', width=20, font=button_font, command=delete_file).place(x=30, y=170)
Button(root, text='Open a folder', width=20, font=button_font, command=open_folder).place(x=30, y=210)
Button(root, text='Delete a folder', width=20, font=button_font, command=delete_folder).place(x=30, y=250)
Button(root, text='Move a folder', width=20, font=button_font, command=move_folder).place(x=30, y=290)
Button(root, text='List all files in a folder', width=20, font=button_font,
command=list_files_in_folder).place(x=30, y=330)
root.update()
root.mainloop()