Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import os
  2. from time import sleep
  3. import stat
  4.  
  5. def is_corrupt(path):
  6.     f = None
  7.     try:
  8.         mode = os.stat(path).st_mode
  9.         if stat.S_ISREG(mode):
  10.             f = open(path, "rb")
  11.             f.read()
  12.         else:
  13.             print("skipping non-regular file at", path)
  14.     except OSError as e:
  15.         sleep(4) #time to remount
  16.         if f is not None:
  17.             f.close()
  18.         return True, e
  19.    
  20.     if f is not None:
  21.         f.close()
  22.     return False, None
  23.  
  24. broken_file = open("/Users/Jack/Desktop/broken.txt", "a")
  25. okay_file = open("/Users/Jack/Desktop/accessible.txt", "a")
  26.  
  27. for root, subdirs, files in os.walk("/Volumes/Macintosh HD"):
  28.     for item in files:
  29.         path = os.path.join(root, item)
  30.         corrupt, e = is_corrupt(path)
  31.        
  32.         if corrupt and e and e.errno == 6:
  33.             print(path, sep="", file=broken_file)
  34.             broken_file.flush()
  35.             print("****", path, "is broken")
  36.            
  37.             sleep(1)
  38.            
  39.             #wait for remount
  40.             while not os.path.exists("/Volumes/Macintosh HD"):
  41.                 continue
  42.         else:
  43.             print(path, file=okay_file)
  44.             okay_file.flush()
  45.            
  46. broken_file.close()
  47. okay_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement