To find the list of all the available drives on...

To find the list of all the available drives on a Windows machine (with Python) you can do the following:

import win32api
s = win32api.GetLogicalDriveStrings().split("\x00")[:-1]

The [:-1] is to drop the last element from the list which will be an empty string. This will give you a list of drive root directories like:

['C:\\', 'D:\\', 'G:\\', 'I:\\', 'S:\\', 'Y:\\', 'Z:\\']

If you need to get the volume label, or some other information about each of these drives you can use the GetVolumeInformation function, like:

t = win32api.GetVolumeInformation("C:\\")

This returns a tupple like:

('MDATA', -590490522, 255, 6, 'FAT32')

where the first element is the label of the drive (which can be handy if you have a few USB drives that Windows insists of giving different drive letters to depending on the order you insert them or power them up and you need to be able to find a particular drive to do some processing on). [7643]

你可能感兴趣的:(To find the list of all the available drives on...)