[ACCEPTED]-Find System Hard Disk Drive from Python?-disk

Accepted answer
Score: 16

This is how to return the letter of the System drive on a Win32 platform:

import os
print os.getenv("SystemDrive")

The above snippet returns the system drive 1 letter. In my case ( and most cases on windows) C:

Score: 2

If you install the win32 extensions, the 4 following will get you the information you 3 want:

In [82]: import win32api

In [83]: drives = win32api.GetLogicalDriveStrings()

In [84]: drives
Out[84]: 'C:\\\x00D:\\\x00E:\\\x00'

In [85]: drives.split('\x00')
Out[85]: ['C:\\', 'D:\\', 'E:\\', '']

Ignore the last item, due to a terminating 2 character in the string returned by win32's 1 GetLogicalDriveStrings function.

More Related questions