Advertisement
Najeebsk

SEARCH-FILES-LIST-TITAL.py

Feb 29th, 2024
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog
  3. import glob
  4. import os
  5.  
  6. def search_files(extension):
  7.     folder_path = filedialog.askdirectory()
  8.     if folder_path:
  9.         file_list = glob.glob(folder_path + f"/*.{extension}")
  10.         with open(f"file_list_{extension}.txt", "w") as file:
  11.             for filepath in file_list:
  12.                 filename = os.path.basename(filepath)
  13.                 file.write(f"Title: {os.path.splitext(filename)[0]}\n{filepath}\n")
  14.         result_label.config(text="File list saved successfully!")
  15.  
  16. # GUI
  17. root = tk.Tk()
  18. root.title("Najeeb File Search")
  19. root.geometry('300x100')
  20.  
  21.  
  22. extension_label = tk.Label(root, text="Enter File Extension Only")
  23. extension_label.pack()
  24.  
  25. extension_entry = tk.Entry(root)
  26. extension_entry.pack()
  27.  
  28. search_button = tk.Button(root, text="Search", command=lambda: search_files(extension_entry.get()))
  29. search_button.pack()
  30.  
  31. result_label = tk.Label(root, text="")
  32. result_label.pack()
  33.  
  34. root.mainloop()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement