Find System Hard Disk Drive from Python?

前端 未结 2 2055
眼角桃花
眼角桃花 2020-12-21 11:18

I am working on a software installer for my current application. It needs to be installed to the System HDD. How owuld I detect the system drive and return the letter from P

2条回答
  •  盖世英雄少女心
    2020-12-21 11:34

    If you install the win32 extensions, the following will get you the information you 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 character in the string returned by win32's GetLogicalDriveStrings function.

提交回复
热议问题