Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from time import sleep
- import stat
- def is_corrupt(path):
- f = None
- try:
- mode = os.stat(path).st_mode
- if stat.S_ISREG(mode):
- f = open(path, "rb")
- f.read()
- else:
- print("skipping non-regular file at", path)
- except OSError as e:
- sleep(4) #time to remount
- if f is not None:
- f.close()
- return True, e
- if f is not None:
- f.close()
- return False, None
- broken_file = open("/Users/Jack/Desktop/broken.txt", "a")
- okay_file = open("/Users/Jack/Desktop/accessible.txt", "a")
- for root, subdirs, files in os.walk("/Volumes/Macintosh HD"):
- for item in files:
- path = os.path.join(root, item)
- corrupt, e = is_corrupt(path)
- if corrupt and e and e.errno == 6:
- print(path, sep="", file=broken_file)
- broken_file.flush()
- print("****", path, "is broken")
- sleep(1)
- #wait for remount
- while not os.path.exists("/Volumes/Macintosh HD"):
- continue
- else:
- print(path, file=okay_file)
- okay_file.flush()
- broken_file.close()
- okay_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement