Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import os, zipfile
  2. from zipfile import BadZipFile
  3.  
  4.  
  5. def listdir(root='.'):
  6. for root, dirs, files in os.walk(root):
  7. for f in files:
  8. print(os.path.join(root, f))
  9. currentfile = os.path.join(root, f)
  10. if currentfile.endswith(".zip"):
  11. unzip(currentfile)
  12. else:
  13. searchfile(currentfile)
  14.  
  15.  
  16. def unzip(file):
  17. try:
  18. file_name = os.path.abspath(file) # get full path of files
  19. zip_ref = zipfile.ZipFile(file_name) # create zipfile object
  20. zip_ref.extractall(dir_name) # extract file to dir
  21. zip_ref.close() # close file
  22. os.remove(file_name) # delete zipped file
  23. except BadZipFile:
  24. pass
  25.  
  26.  
  27. def searchfile(file):
  28. user_name = "GailOllis"
  29. with open(file, 'r') as f:
  30. count = 0
  31. for x, line in enumerate(f):
  32. splitLine = line.split()
  33. print(splitLine)
  34. for splitLinePOS in range(0, len(splitLine)):
  35. if splitLine[splitLinePOS] == user_name:
  36. foundPass = splitLinePOS + 1
  37. if x == foundPass:
  38. with open("GailOllisPasswords.txt", "w+") as passwords:
  39. passwords.write("Password found for username: " + user_name + "\n")
  40. passwords.write("Password is: " + str(splitLine[1]) + "\n")
  41.  
  42.  
  43. listdir(".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement