Python - How to get driver names C: D: F: I:

Asked

Viewed 62 times

1

inserir a descrição da imagem aqui

I’m developing a GUI in Python 3.6 using TKinter. I have reached an impasse where I have to get the letters of the installed drivers and their names the same way they appear in Windows Explorer. See attached figure.

With the code below I can get the driver letters, but not the names.

drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]

Someone’s been through this trouble?

  • Something like win32api.GetVolumeInformation("C:\\") resolves?

  • Anderson, "win32api.Getvolumeinformation("C: ")" only works for drive C:. Does not display other driver names.

  • You tried to replace the driver letter in order to get the data from others, such as win32api.GetVolumeInformation("D:\\")? In fact, do not use the answer field for comments, for such, use the comment field (just below the question has the link comment on).

  • ('Win7', 1087985650, 255, 65470719, 'NTFS') ('554', 4258, 255, 262382, 'NTFS') (', -790939965, 255, 13041919, 'NTFS'')

  • @rbarreto has any doubts? One question you are Renato right?

  • 1

    Hello Renato and @rbarreto! If these accounts are the same please confirm here to help you join them in one. See you soon!

  • To merge the accounts contact us and make a request

Show 2 more comments

1 answer

2

As Anderson suggested, use win32api.GetVolumeInformation, just iterate with the for, thus:

import win32api

drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')

for drive in drives:
    try:
        print(win32api.GetVolumeInformation(drive.strip()))
    except:
        pass

Browser other questions tagged

You are not signed in. Login or sign up in order to post.