Skip to content
Advertisement

How can I get a list of removable drives plugged in the computer?

I would like to get a list of the removable drivers that are plugged in to the computer.

I think it can be done by using some registry, but I don’t know how exactly.

If there is another way I would like to hear about it.

Note: It’s important that I will be able to separate the removable drives from the fixed drives.

Advertisement

Answer

The algorithm is straightforward:

This is how it looks in Python (using PyWin32 wrappers). Add any of win32con.DRIVE_* constants to drive_types tuple to get different drive types combinations:

code00.py:

JavaScript

Output:

JavaScript

As a side note, in my environment (at this point):

  • D: is a partition on an external (USB) HDD

  • H:, I: are partitions on a bootable USB stick (UEFI)

  • The rest are partitions on the (internal) SSD and / or HDD disks

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement