Advertisement
Vincent38190

Untitled

Oct 18th, 2022
1,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | Software | 0 0
  1. import argparse
  2. from genericpath import isfile
  3. import os
  4.  
  5.  
  6. def parse():
  7.     parser = argparse.ArgumentParser()
  8.     parser.add_argument("folders", nargs="+", help="paths vers dossiers à check")
  9.    
  10.     return parser.parse_args()
  11.  
  12. def file_found_rec(path, fileList, fileDoublon):
  13.     for file in os.listdir(path):
  14.         new_path = os.path.join(path, file)
  15.         if os.path.isfile(new_path):
  16.             if not file in fileList:
  17.                 fileList.append(file)
  18.             else:
  19.                 fileDoublon.append(file)
  20.         if os.path.isdir(new_path):
  21.             file_found_rec(new_path, fileList, fileDoublon)
  22.  
  23. def main():
  24.     args = parse()
  25.     fileFounded = []
  26.     fileDoublon = []
  27.     for folder in args.folders:
  28.         file_found_rec(folder, fileFounded, fileDoublon)
  29.     print(f"Fichiers trouvés: {fileFounded}")
  30.     print(f"Fichiers doublon: {fileDoublon}")
  31.  
  32. if __name__=="__main__":
  33.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement