Терминальный проект КиберПлат [open source]
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.1KB

  1. import io
  2. import os
  3. # Windows filesystem ONLY
  4. # for linux remove .lower() calls
  5. def get_public_filenames():
  6. f = open('filelist.txt', 'r')
  7. x = f.readlines()
  8. result = []
  9. for l in x:
  10. result.append(l.strip().lower())
  11. return result
  12. def get_all_files():
  13. files = []
  14. for (dirpath, dirnames, filenames) in os.walk("."):
  15. path = dirpath.replace(".\\", "/").replace("\\", "/")
  16. for f in filenames:
  17. if path == ".":
  18. files.append("/" + f.lower())
  19. else:
  20. files.append(path.lower() + "/" + f.lower())
  21. return files
  22. def is_dir(p):
  23. return os.path.isdir(os.getcwd() + p.replace("/", "\\"))
  24. public_files = set(get_public_filenames())
  25. removed_counter = 0
  26. for f in get_all_files():
  27. is_public = f in public_files
  28. if is_public:
  29. continue
  30. ff = f.split("/")
  31. for i in range(2, len(ff) + 1):
  32. path = "/".join(ff[0:i])
  33. path = path + "/" if is_dir(path) else path
  34. is_public = is_public or (path in public_files)
  35. if is_public:
  36. break
  37. if is_public:
  38. continue
  39. os.remove(os.getcwd() + f.replace("/", "\\"))
  40. removed_counter += 1
  41. print("Files removed: {}".format(removed_counter))