0

With my program I want to check if there are other hard drives connected to the computer, and then I want the program to print the names of those hard drives (like C:)

The hard drive I'm now working on is called C:, but I also have a drive connected to the computer called D:.

How do I let my program find out all the other hard drives connected?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87

1 Answers1

1
import win32api
import win32file
if sys.platform == 'win32':
    return [drive for drive in win32api.GetLogicalDriveStrings() if
                re.match(r"^[A-Z]+", drive) and win32file.GetDriveType(drive + ":" + "//") == win32file.DRIVE_FIXED]

You can use this to find all fixed drives and not CD drives or USB drives

vks
  • 67,027
  • 10
  • 91
  • 124