Advertisement
DrAungWinHtut

str.py

Jan 24th, 2025
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import os
  2. from icecream.icecream import ic
  3.  
  4. # Get the absolute path of the current source file
  5. source_file_path = os.path.abspath(__file__)
  6.  
  7. lst = source_file_path.split("\\")
  8.  
  9. n = len(lst)
  10.  
  11. ic(n)
  12. # folders = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))]
  13.  
  14. # D:\python3\py\str.py
  15. filename = lst.pop()
  16. lst.pop()
  17.  
  18. ic(lst)
  19.  
  20. path1 = ""
  21.  
  22. for p in lst:
  23.     path1 = path1 + p + "\\"
  24.  
  25. ic(path1)
  26.  
  27.  
  28. foldersNfiles = os.listdir(path1)
  29. folders = []
  30.  
  31. for f in foldersNfiles:
  32.     if os.path.isdir(os.path.join(path1, f)):
  33.         folders.append(os.path.join(path1, f))
  34.  
  35.  
  36. ic(folders)
  37.  
  38.  
  39. for ff in folders:
  40.     file_path = os.path.join(ff, filename)
  41.     if file_path != source_file_path:
  42.         command = "copy " + source_file_path + " " + file_path
  43.         ic(command)
  44.         os.system(command)
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement