Advertisement
MizunoBrasil

Organização de Arquivos

Jun 23rd, 2023 (edited)
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.50 KB | None | 0 0
  1. import os
  2. import shutil
  3. from tqdm import tqdm
  4.  
  5. print("Organização de Arquivos")
  6.  
  7. def move_files_to_images_folder():
  8.     current_path = os.getcwd()
  9.     images_folder = os.path.join(current_path, "Imagens")
  10.     if not os.path.exists(images_folder):
  11.         os.makedirs(images_folder)
  12.  
  13.     files = os.listdir(current_path)
  14.     image_files = [file for file in files if file.lower().endswith((".png", ".jpg", ".jpeg"))]
  15.  
  16.     for file in tqdm(image_files, desc="Movendo arquivos"):
  17.         file_path = os.path.join(current_path, file)
  18.         destination_path = os.path.join(images_folder, file)
  19.         shutil.move(file_path, destination_path)
  20.  
  21.     print("Arquivos movidos com sucesso para a subpasta 'Imagens'.")
  22.  
  23. def move_files_to_icons_folder():
  24.     current_path = os.getcwd()
  25.     icons_folder = os.path.join(current_path, "Icones")
  26.     if not os.path.exists(icons_folder):
  27.         os.makedirs(icons_folder)
  28.  
  29.     files = os.listdir(current_path)
  30.     icon_files = [file for file in files if file.lower().endswith(".ico")]
  31.  
  32.     for file in tqdm(icon_files, desc="Movendo arquivos"):
  33.         file_path = os.path.join(current_path, file)
  34.         destination_path = os.path.join(icons_folder, file)
  35.         shutil.move(file_path, destination_path)
  36.  
  37.     print("Arquivos movidos com sucesso para a subpasta 'Icones'.")
  38.  
  39. def move_files_to_archives_folder():
  40.     current_path = os.getcwd()
  41.     archives_folder = os.path.join(current_path, "Compactados")
  42.     if not os.path.exists(archives_folder):
  43.         os.makedirs(archives_folder)
  44.  
  45.     files = os.listdir(current_path)
  46.     archive_files = [file for file in files if file.lower().endswith((".zip", ".rar"))]
  47.  
  48.     for file in tqdm(archive_files, desc="Movendo arquivos"):
  49.         file_path = os.path.join(current_path, file)
  50.         destination_path = os.path.join(archives_folder, file)
  51.         shutil.move(file_path, destination_path)
  52.  
  53.     print("Arquivos movidos com sucesso para a subpasta 'Compactados'.")
  54.  
  55. def move_files_to_videos_folder():
  56.     current_path = os.getcwd()
  57.     videos_folder = os.path.join(current_path, "Videos")
  58.     if not os.path.exists(videos_folder):
  59.         os.makedirs(videos_folder)
  60.  
  61.     files = os.listdir(current_path)
  62.     video_files = [file for file in files if file.lower().endswith((".mp4", ".mkv", ".ts", ".flv", ".mov"))]
  63.  
  64.     for file in tqdm(video_files, desc="Movendo arquivos"):
  65.         file_path = os.path.join(current_path, file)
  66.         destination_path = os.path.join(videos_folder, file)
  67.         shutil.move(file_path, destination_path)
  68.  
  69.     print("Arquivos movidos com sucesso para a subpasta 'Videos'.")
  70.  
  71. def move_files_to_text_documents_folder():
  72.     current_path = os.getcwd()
  73.     text_documents_folder = os.path.join(current_path, "Textos e Documentos")
  74.     if not os.path.exists(text_documents_folder):
  75.         os.makedirs(text_documents_folder)
  76.  
  77.     files = os.listdir(current_path)
  78.     text_doc_files = [file for file in files if file.lower().endswith((".txt", ".doc", ".pdf"))]
  79.  
  80.     for file in tqdm(text_doc_files, desc="Movendo arquivos"):
  81.         file_path = os.path.join(current_path, file)
  82.         destination_path = os.path.join(text_documents_folder, file)
  83.         shutil.move(file_path, destination_path)
  84.  
  85.     print("Arquivos movidos com sucesso para a subpasta 'Textos e Documentos'.")
  86.  
  87. def move_files_to_dvd_folder():
  88.     current_path = os.getcwd()
  89.     dvd_folder = os.path.join(current_path, "Filmes DVD-R")
  90.     if not os.path.exists(dvd_folder):
  91.         os.makedirs(dvd_folder)
  92.  
  93.     files = os.listdir(current_path)
  94.     dvd_files = [file for file in files if file.lower().endswith(".iso")]
  95.  
  96.     for file in tqdm(dvd_files, desc="Movendo arquivos"):
  97.         file_path = os.path.join(current_path, file)
  98.         destination_path = os.path.join(dvd_folder, file)
  99.         shutil.move(file_path, destination_path)
  100.  
  101.     print("Arquivos movidos com sucesso para a subpasta 'Filmes DVD-R'.")
  102.  
  103. def move_files_to_programming_folder():
  104.     current_path = os.getcwd()
  105.     programming_folder = os.path.join(current_path, "Programação PHP")
  106.     if not os.path.exists(programming_folder):
  107.         os.makedirs(programming_folder)
  108.  
  109.     files = os.listdir(current_path)
  110.     programming_files = [file for file in files if file.lower().endswith((".php", ".sql"))]
  111.  
  112.     for file in tqdm(programming_files, desc="Movendo arquivos"):
  113.         file_path = os.path.join(current_path, file)
  114.         destination_path = os.path.join(programming_folder, file)
  115.         shutil.move(file_path, destination_path)
  116.  
  117.     print("Arquivos movidos com sucesso para a subpasta 'Programação PHP'.")
  118.  
  119. def move_files_to_music_folder():
  120.     current_path = os.getcwd()
  121.     music_folder = os.path.join(current_path, "Músicas")
  122.     if not os.path.exists(music_folder):
  123.         os.makedirs(music_folder)
  124.  
  125.     files = os.listdir(current_path)
  126.     music_files = [file for file in files if file.lower().endswith((".mp3", ".wav", ".flac"))]
  127.  
  128.     for file in tqdm(music_files, desc="Movendo arquivos"):
  129.         file_path = os.path.join(current_path, file)
  130.         destination_path = os.path.join(music_folder, file)
  131.         shutil.move(file_path, destination_path)
  132.  
  133.     print("Arquivos movidos com sucesso para a subpasta 'Músicas'.")
  134.  
  135. def show_menu():
  136.     print("1 - Mover extensão .png, .jpg, .jpeg")
  137.     print("2 - Mover extensão .ico")
  138.     print("3 - Mover extensão .zip, .rar")
  139.     print("4 - Mover extensão .mp4, .mkv, .ts, .flv, .mov")
  140.     print("5 - Mover extensão .txt, .doc, .pdf")
  141.     print("6 - Mover extensão .iso")
  142.     print("7 - Mover extensão .php, .sql")
  143.     print("8 - Mover extensão .mp3, .wav, .flac")
  144.     print("9 - Sair (Pressione a barra de espaço para fechar)")
  145.  
  146. def main():
  147.     while True:
  148.         show_menu()
  149.         choice = input("Escolha uma opção: ")
  150.  
  151.         if choice == "1":
  152.             move_files_to_images_folder()
  153.         elif choice == "2":
  154.             move_files_to_icons_folder()
  155.         elif choice == "3":
  156.             move_files_to_archives_folder()
  157.         elif choice == "4":
  158.             move_files_to_videos_folder()
  159.         elif choice == "5":
  160.             move_files_to_text_documents_folder()
  161.         elif choice == "6":
  162.             move_files_to_dvd_folder()
  163.         elif choice == "7":
  164.             move_files_to_programming_folder()
  165.         elif choice == "8":
  166.             move_files_to_music_folder()
  167.         elif choice == "9":
  168.             break
  169.         else:
  170.             print("Opção inválida. Tente novamente.")
  171.  
  172. if __name__ == "__main__":
  173.     main()
  174.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement