forked from Shammapraveen/DevIncept
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_Manager.py
More file actions
107 lines (80 loc) · 3 KB
/
File_Manager.py
File metadata and controls
107 lines (80 loc) · 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from tkinter import *
from PIL import ImageTk, Image
import shutil
import os
from tkinter import filedialog
from tkinter import messagebox as mb
import easygui
# Major functions of file manager
# open a file box window
# when we want to select a file
def open_window():
read=easygui.fileopenbox()
return read
# open file function
def open_file():
string = open_window()
try:
os.startfile(string)
except:
mb.showinfo('confirmation', "File not found!")
# copy file function
def copy_file():
source1 = open_window()
destination1=filedialog.askdirectory()
shutil.copy(source1,destination1)
mb.showinfo('confirmation', "File Copied !")
# delete file function
def delete_file():
del_file = open_window()
if os.path.exists(del_file):
os.remove(del_file)
else:
mb.showinfo('confirmation', "File not found !")
# rename file function
def rename_file():
chosenFile = open_window()
path1 = os.path.dirname(chosenFile)
extension=os.path.splitext(chosenFile)[1]
print("Enter new name for the chosen file")
newName=input()
path = os.path.join(path1, newName+extension)
print(path)
os.rename(chosenFile,path)
mb.showinfo('confirmation', "File Renamed !")
# move file function
def move_file():
source = open_window()
destination =filedialog.askdirectory()
if(source==destination):
mb.showinfo('confirmation', "Source and destination are same")
else:
shutil.move(source, destination)
mb.showinfo('confirmation', "File Moved !")
# function to remove a folder
def remove_folder():
delFolder = filedialog.askdirectory()
os.rmdir(delFolder)
mb.showinfo('confirmation', "Folder Deleted !")
# function to list all the files in folder
def list_files():
folderList = filedialog.askdirectory()
sortlist=sorted(os.listdir(folderList))
i=0
print("Files in ", folderList, "folder are:")
while(i<len(sortlist)):
print(sortlist[i]+'\n')
i+=1
# UI for file manager
root = Tk()
# creating label and buttons to perform operations
Label(root, text="File Manager", font=("Helvetica", 16), fg="blue").grid(row = 5, column = 2)
Button(root, text = "Open a File", command = open_file).grid(row=20, column =2)
Button(root, text = "Copy a File", command = copy_file).grid(row = 20, column = 4)
Button(root, text = "Delete a File", command = delete_file).grid(row = 40, column = 2)
Button(root, text = "Rename a File", command = rename_file).grid(row = 40, column = 4)
Button(root, text = "Move a File", command = move_file).grid(row = 60, column =2)
Button(root, text = "Make a Folder", command = make_folder).grid(row = 60, column = 4)
Button(root, text = "Remove a Folder", command = remove_folder).grid(row = 80, column =2)
Button(root, text = "List all Files in Directory", command = list_files).grid(row = 80,column = 4)
root.mainloop()