Advertisement
egor230

Найти значки

Jul 13th, 2024 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | Source Code | 0 0
  1. import shutil, subprocess, time, os
  2. '''
  3. Этот код будет искать значки (файлы с расширениями .jpg, .jpeg, .png, .gif, .bmp) в папке source_folder и копирует их в папку icon_find
  4. '''
  5. find_name= str(input())
  6. #find_name= "wo"
  7. backup_script_path = f'''#!/bin/bash
  8. current_user=$(whoami);
  9. echo $current_user
  10. exit;# Завершаем выполнение скрипта
  11. '''
  12. # Вызываем скрипт
  13. user = subprocess.run(['bash'], input=backup_script_path , stdout=subprocess.PIPE, text=True).stdout.strip()
  14. def find_images(folder_path, find_name=None):
  15.   image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp']  # список расширений изображений
  16.   image_files = []  # список для хранения имен изображений
  17.   find_name=find_name.lower()
  18.   for root, dirs, files in os.walk(folder_path):
  19.    for file in files:
  20.       _, ext = os.path.splitext(file)
  21.       if ext.lower() in image_extensions:
  22.         file1 =file.lower()
  23.         if find_name in file1:
  24.            file= root + str("/")+file
  25.            image_files.append(file)
  26.   return image_files
  27.  
  28. folder_path="/home/{}/.local/share/icons/hicolor".format(user)# print(folder_path)
  29. image_list = find_images(folder_path, find_name)# print(image_list)
  30. folder_path1 = "icon_find"
  31.  
  32. # Проверка наличия папки
  33. if not os.path.exists(folder_path1):
  34.     # Создание папки
  35.     os.makedirs(folder_path1)
  36. current_dir = os.getcwd()
  37. current_dir = current_dir+str("/")+folder_path1# print(current_dir)
  38. # # Копирование файлов из списка image_list в текущую директорию
  39. for file_name in image_list:
  40.   file_name1 = os.path.basename(file_name)  # Извлечение имени файла из полного пути
  41.   dest_file = os.path.join(current_dir, file_name1)  # print(file_name)  # print(dest_file)
  42.   shutil.copyfile(file_name, dest_file)
  43.  
  44. subprocess.call(["xdg-open", folder_path1])  #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement