Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. # grab the folder you want to organize with a prompt
  2. from tkinter import Tk
  3. from tkinter.filedialog import askdirectory
  4. import os
  5.  
  6. path = askdirectory(title='Select Folder')
  7. listing = os.listdir(path)
  8.  
  9. # path = "/Users/tomer/Desktop/Organizer Python Project/Test folder"
  10. # path_item_list = os.listdir("/Users/tomer/Desktop/Organizer Python Project/Test folder")
  11.  
  12. # initiate the name and extensions lists
  13. names = []
  14. exts = []
  15.  
  16. # append the files and their extensions to the lists
  17.  
  18. # for i in listing:
  19. #     clean_name = os.path.splitext(i)[0]
  20. #     name.append(clean_name)
  21. #     extension = os.path.splitext(i)[1].replace('.', '')
  22. #     if extension not in exts:
  23. #         exts.append(extension)
  24. #     exts = list(filter(None, exts))
  25.  
  26.  
  27. # create new folders with the name of each extension
  28.  
  29. # for ext in exts:
  30. #     full_path = os.path.join(path, ext)
  31. #     os.makedirs(full_path)
  32.  
  33. # grab the files by extension and move them to the new folders
  34.  
  35.  
  36. # ====================
  37.  
  38. for filename in listing:
  39.     clean_name, extension = os.path.splitext(filename)
  40.     names.append(clean_name)
  41.     extension = extension.replace('.', '')
  42.     if extension not in exts:
  43.         exts.append(extension)
  44.  
  45. # create new folders with the name of each extension
  46. for ext in exts:
  47.     full_path = os.path.join(path, ext)
  48.     os.makedirs(full_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement