Dhroov Assignment10
Dhroov Assignment10
Name: Atharva
Dhroov S. Humane
WaddDesai
Reg No: 221070028
221070076
Theory:
2. File Attributes: Each file in a file system is associated with various attributes,
including:
● Name: The unique identifier of the file.
● Size: The size of the file in bytes.
● Type: The type of file (e.g., text file, executable file, directory).
● Location: The physical location of the file on the storage device.
● Permissions: Access control information specifying who can read, write, or
execute the file.
● Timestamps: Information about when the file was created, modified, or
accessed.
import os
import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog
class FileExplorer(tk.Tk):
def __init__(self):
super().__init__()
self.title("File Explorer")
self.geometry("800x600")
self.current_directory = os.getcwd()
self.setup_ui()
self.load_directory(self.current_directory)
def setup_ui(self):
self.current_dir_frame = tk.Frame(self)
self.current_dir_frame.pack(pady=10, fill=tk.X)
self.current_dir_label = tk.Label(self.current_dir_frame,
text=self.current_directory, font=("Arial", 12))
self.current_dir_label.pack(side=tk.LEFT, fill=tk.X, expand=True)
self.scrollbar_dir = tk.Scrollbar(self.current_dir_frame,
orient=tk.HORIZONTAL, command=self._on_scroll_dir)
self.scrollbar_dir.pack(side=tk.BOTTOM, fill=tk.X)
self.file_list_frame = tk.Frame(self)
self.file_list_frame.pack(expand=True, fill=tk.BOTH)
self.file_listbox = tk.Listbox(self.file_list_frame, width=70, height=20,
font=("Arial", 12))
self.file_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
self.scrollbar = tk.Scrollbar(self.file_list_frame, orient=tk.VERTICAL,
command=self.file_listbox.yview)
self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.file_listbox.config(yscrollcommand=self.scrollbar.set)
self.file_listbox.bind("<Double-Button-1>", self.open_selected_item)
self.button_frame = tk.Frame(self)
self.button_frame.pack(pady=10)
button_width = 12
button_padx = 10
button_pady = 5
items = os.listdir(directory)
folders = [item for item in items if os.path.isdir(os.path.join(directory,
item))]
files = [item for item in items if os.path.isfile(os.path.join(directory,
item))]
folders.sort()
files.sort()
def ask_create_folder(self):
new_folder_name = simpledialog.askstring("Create Folder", "Enter folder
name:")
if new_folder_name:
new_folder_path = os.path.join(self.current_directory, new_folder_name)
os.makedirs(new_folder_path, exist_ok=True)
self.load_directory(self.current_directory)
def ask_create_file(self):
new_file_name = simpledialog.askstring("Create File", "Enter file name:")
if new_file_name:
new_file_path = os.path.join(self.current_directory, new_file_name)
with open(new_file_path, 'w') as new_file:
pass
self.load_directory(self.current_directory)
def ask_rename(self):
selected_item = self.file_listbox.get(tk.ACTIVE)
if selected_item and "[Folder]" not in selected_item:
new_name = simpledialog.askstring("Rename", f"Enter new name for
{selected_item}:")
if new_name:
old_path = os.path.join(self.current_directory, selected_item)
new_path = os.path.join(self.current_directory, new_name)
os.rename(old_path, new_path)
self.load_directory(self.current_directory)
def delete_file(self):
selected_item = self.file_listbox.get(tk.ACTIVE)
if selected_item:
confirmation = messagebox.askyesno("Confirm Deletion", f"Are you sure
you want to delete {selected_item}?")
if confirmation:
file_path = os.path.join(self.current_directory,
selected_item.split(" [Folder]")[0])
if os.path.isdir(file_path):
os.rmdir(file_path)
else:
os.remove(file_path)
self.load_directory(self.current_directory)
def go_back(self):
parent_dir = os.path.abspath(os.path.join(self.current_directory,
os.pardir))
self.load_directory(parent_dir)
if __name__ == "__main__":
app = FileExplorer()
app.mainloop()
Output:
Conclusion: Thus we have successfully created and implemented a GUI that can
perform CRUD operations on File/Folders in a File System.