I want to fetch all the local disks and their partitions then as a result return all the data like "total space, used space and free space". The problem is to check if the partition is exist then continue to end if not through error.
In the code below, my local disk has three partitions: C:\, D:\, F:\ . However, partition G:\ is not exist so it is hang then closed.
I am using Python 3.6 and Pycharm community.
def disk_usage(self):
disks = ['C','D','F','G']
for i in disks:
total, used, free = shutil.disk_usage(i+":\\")
try:
print("Drive " + i + " as follows:")
print("==================")
print("Total: %d GB" % (total // (2**30)))
print("Used: %d GB" % (used // (2**30)))
print("Free: %d GB" % (free // (2**30)))
print("===========")
print("")
except GetoptError as err:
print(err)
Thanks in advance,