Please use the below script to check for disk issues
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
import subprocess
disNam = 'C:' ##if the disNam has null value, script will execute at current directory
dObj = subprocess.Popen('wmic logicaldisk get deviceid, drivetype', shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
driNams = dObj.communicate()
driNams = driNams[0].split('
')[1:]
valDriNams = []
for i in driNams:
if i.strip() != '' and '3' in i.strip():
valDriNams.append(i.split(' ')[0].strip())
##print valDriNams
if disNam in valDriNams:
print '{} is valid and we start checking for problems...'.format(disNam)
pObj = subprocess.Popen('chkdsk '+disNam, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
chkRes = pObj.communicate()
print chkRes[0]
elif disNam == '':
pObj = subprocess.Popen('chkdsk', shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
chkRes = pObj.communicate()
print chkRes[0]
else:
print '{} is not valid, try again with only local disks ie any one from the list:- {}'.format(disNam, ', '.join(valDriNams))
Sample Output: