Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog
- import glob
- import os
- def search_files(extension):
- folder_path = filedialog.askdirectory()
- if folder_path:
- file_list = glob.glob(folder_path + f"/*.{extension}")
- with open(f"file_list_{extension}.txt", "w") as file:
- for filepath in file_list:
- filename = os.path.basename(filepath)
- file.write(f"Title: {os.path.splitext(filename)[0]}\n{filepath}\n")
- result_label.config(text="File list saved successfully!")
- # GUI
- root = tk.Tk()
- root.title("Najeeb File Search")
- root.geometry('300x100')
- extension_label = tk.Label(root, text="Enter File Extension Only")
- extension_label.pack()
- extension_entry = tk.Entry(root)
- extension_entry.pack()
- search_button = tk.Button(root, text="Search", command=lambda: search_files(extension_entry.get()))
- search_button.pack()
- result_label = tk.Label(root, text="")
- result_label.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement