How to get windows disk device instance path by python?
Posted: Thu Jan 02, 2020 2:50 am
Hi,How to get windows disk device instance path by python?
Please see the new forum at
https://forum.micropython.org/
Code: Select all
import os
os.popen('wmic diskdrive get PNPDeviceID').read()
Thank you very much. Python use code:os.popen('wmic diskdrive').read() . I can get the disk DeviceID and PNPDeviceID. Then I have a new question: How do I know the partition(like:C,D,E,F,G...) of this disk device if I know the DeviceID and PNPDeviceID?stijn wrote: ↑Thu Jan 02, 2020 8:28 amYou mean Python or MicroPython?
First case you can parse output of e.g.
(your question doesn't specify which device, this will list all of them..)Code: Select all
import os os.popen('wmic diskdrive get PNPDeviceID').read()
Second case: you'll have to write something custom for that since popen isn't implemented. E.g. a custom C module which uses win32 API to get the needed information.
Thank you very much.Helped me a lot.stijn wrote: ↑Thu Jan 02, 2020 1:03 pmSomething like this: https://superuser.com/questions/634842/ ... using-wmic or maybe using the Python psutil module