Advertisement
FlyFar

gui/FileExplorer.py

Aug 10th, 2023
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | Cybersecurity | 0 0
  1. import os, getpass
  2. from glob import glob
  3. from zipfile import ZipFile
  4.  
  5. class FileExplorer:
  6.    
  7.    
  8.     @staticmethod
  9.     def WriteToFile(result):
  10.         with open("result.txt","w") as file:
  11.             for element in result:
  12.                 print(element)
  13.                 file.write(element + "\n")
  14.  
  15.    
  16.     @staticmethod
  17.     def DiscoverDirectory(path):
  18.         content = os.listdir(path)
  19.         FileExplorer.WriteToFile(content)
  20.  
  21.  
  22.     @staticmethod
  23.     def SearchForFile(pattern):
  24.         resultSet = glob(pattern,recursive=True)
  25.         FileExplorer.WriteToFile(resultSet)
  26.         return resultSet
  27.  
  28.  
  29.     @staticmethod
  30.     def archive(files_to_archive):
  31.         with ZipFile("D:\\hello.zip", "w") as archive:
  32.             for file in files_to_archive:
  33.                 archive.write(file)
  34.  
  35. #-------------------------------------------------------
  36.  
  37. if __name__ == "__main__":
  38.     path_with_pattern = input("Path with pattern?: ")
  39.     files_to_archive = FileExplorer.SearchForFile(path_with_pattern)
  40.     FileExplorer.archive(files_to_archive)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement