-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileexplorer.py
93 lines (93 loc) · 3.04 KB
/
fileexplorer.py
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
import os
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox as mb
import easygui
import shutil
#Saving a file
def Save():
def SaveAs():
FileName = filedialog.asksaveasfile(initialdir="/",defaultextension='.txt',filetypes=[("text files",".txt"),("all files",".*")])
FileText=str(textspace.get(1.0,END))
FileName.write(FileText)
Screen.destroy()
SaveWindow= Tk()
button = Button(text="SaveAs", command=SaveAs)
button.pack()
textspace = Text(SaveWindow)
textspace.pack()
#opening a file
def Open():
Read=easygui.fileopenbox()
try:
os.startfile(Read)
except:
mb.showinfo("file not found")
#Renaming a file
def Rename():
Read=easygui.fileopenbox()
pathnew = os.path.dirname(Read)
extension=os.path.splitext(Read)[1]
print("Enter new name of the file")
newName=input()
path1 = os.path.join(pathnew, newName+extension)
print(path1)
os.rename(Read,path1)
mb.showinfo("File Renamed !")
#deleting a file
def Delete():
Read=easygui.fileopenbox()
if os.path.exists(Read):
os.remove(Read)
else:
mb.showinfo("File not found , please check!")
#copying a file
def Copy():
Read=easygui.fileopenbox()
destination1=filedialog.askdirectory()
shutil.copy(Read,destination1)
mb.showinfo("File successfully copied ")
#deleting a folder
def DeleteFolder():
DelFolder = filedialog.askdirectory()
os.rmdir(DelFolder)
mb.showinfo("Folder successfully deleted")
#creating a folder
def CreateFolder():
Folder = filedialog.askdirectory()
print("Enter a name for the folder")
NewFolder=input()
path = os.path.join(Folder, NewFolder)
os.mkdir(path)
mb.showinfo("Folder created successfully")
#Moving the file
def MoveFile():
Read=easygui.fileopenbox()
Destination =filedialog.askdirectory()
if(Read==Destination):
mb.showinfo('confirmation', "Source and destination are same")
else:
shutil.move(Read, Destination)
mb.showinfo("File has moved successfully")
#creating buttons and Initializing window
Screen=Tk()
Screen.title("File Explorer")
Screen.geometry("400x400")
Screen.config(bg="silver")
SaveButton = Button(text="Save",command=Save)
SaveButton.place(relx=0.3,rely=0.2)
OpenButton = Button(text="Open",command=Open)
OpenButton.place(relx=0.5,rely=0.2)
RenameButton = Button(text="Rename",command=Rename)
RenameButton.place(relx=0.3,rely=0.4)
CopyButton = Button(text="Copy",command=Copy)
CopyButton.place(relx=0.5,rely=0.4)
DeleteButton = Button(text="Delete File",command=Delete)
DeleteButton.place(relx=0.3,rely=0.6)
DeleteFolderButton = Button(text="Delete Folder",command=DeleteFolder)
DeleteFolderButton.place(relx=0.5,rely=0.6)
CreateFolderButton = Button(text="Create Folder",command=Rename)
CreateFolderButton.place(relx=0.3,rely=0.8)
MoveFileButton = Button(text="Move File",command=MoveFile)
MoveFileButton.place(relx=0.5,rely=0.8)
mainloop()