From 4775d0db3468e355a88a6093c7d230c8053ba092 Mon Sep 17 00:00:00 2001 From: erew123 <35898566+erew123@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:30:02 +0100 Subject: [PATCH] work around locked drive letters --- diagnostics.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diagnostics.py b/diagnostics.py index f7c42ec..f1f03b0 100644 --- a/diagnostics.py +++ b/diagnostics.py @@ -110,8 +110,14 @@ def get_disk_info(): disk_info = [] partitions = psutil.disk_partitions() for p in partitions: - usage = psutil.disk_usage(p.mountpoint) - disk_info.append(f" Drive: {p.device} | Total: {usage.total / (1024 ** 3):.2f} GB | Used: {usage.used / (1024 ** 3):.2f} GB | Free: {usage.free / (1024 ** 3):.2f} GB | Type: {p.fstype}") + try: + usage = psutil.disk_usage(p.mountpoint) + disk_info.append( + f"Drive: {p.device} | Total: {usage.total / (1024 ** 3):.2f} GB | Used: {usage.used / (1024 ** 3):.2f} GB | Free: {usage.free / (1024 ** 3):.2f} GB | Type: {p.fstype}" + ) + except PermissionError: + # Handle the case where the drive is locked or inaccessible + disk_info.append(f"Drive: {p.device} | Inaccessible or locked") return disk_info def is_port_in_use(port):