forked from nikhilkumarsingh/RemotePy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
27 lines (21 loc) · 1.15 KB
/
file.py
File metadata and controls
27 lines (21 loc) · 1.15 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
import tkinter
from tkinter import filedialog
def chooseFile(UPLOAD_FOLDER):
window = tkinter.Tk()
file_path = filedialog.askopenfilename(initialdir=UPLOAD_FOLDER, title='Choose a file') # check file address (name)
if file_path != "": # Full address of the file, ex: F:/data/uploads/oppo123.jpg
print("%s is chosen" % file_path)
file_path_new = file_path.replace('/', '*') # Change / to * for the string on address bar
window.after(1000, lambda: window.destroy()) # Destroy the widget (tk window) after 1 seconds to run next line
window.mainloop()
return file_path_new
else: # No file is chosen
print("No file is chosen")
window.after(1000, lambda: window.destroy()) # Destroy the widget after 1 seconds
window.mainloop()
return file_path # Return empty string as name
def file_name_from_path(file_path):
path_list = file_path.split('/') # Split full address into list, ex: ["F:", "data", "uploads" ,"oppo123.jpg"]
file_name = path_list[len(path_list) - 1] # File name in last position of the list
print("File's name is: %s", file_name)
return file_name