Advertisement
plarmi

threading3

Apr 22nd, 2024 (edited)
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. """
  2. Пользователь с клавиатуры вводит путь к существующей директории и к новой директории. После чего
  3. запускается поток, который должен скопировать содержимое директории в новое место. Необходимо сохранить
  4. структуру директории. На экран необходимо отобразить
  5. статистику выполненных операций.
  6. """
  7. import threading
  8. import os
  9. import shutil
  10.  
  11. current_directory = input("Введите путь к существующей директории: ").replace("\"", "")
  12. new_directory = input("Введите путь к новой директории: ").replace("\"", "")
  13.  
  14. def copy_directory(src, dst):
  15.     if not os.path.exists(dst):
  16.         os.makedirs(dst)
  17.  
  18.     for item in os.listdir(src):
  19.         current_item = os.path.join(src, item)
  20.         new_item = os.path.join(dst, item)
  21.  
  22.         if os.path.isdir(current_item):
  23.             copy_directory(current_item, new_item)
  24.         else:
  25.             shutil.copy2(current_item, new_item)
  26.  
  27. if not os.path.exists(current_directory):
  28.     print(f"Директория {current_directory} не существует!")
  29. else:
  30.     thread = threading.Thread(target=copy_directory, args=[current_directory, new_directory])
  31.     thread.start()
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement