How to get windows disk device instance path by python?

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
zfm076
Posts: 16
Joined: Mon Dec 30, 2019 8:06 am

How to get windows disk device instance path by python?

Post by zfm076 » Thu Jan 02, 2020 2:50 am

Hi,How to get windows disk device instance path by python?

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: How to get windows disk device instance path by python?

Post by stijn » Thu Jan 02, 2020 8:28 am

You mean Python or MicroPython?

First case you can parse output of e.g.

Code: Select all

import os
os.popen('wmic diskdrive get PNPDeviceID').read() 
(your question doesn't specify which device, this will list all of them..)

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.

zfm076
Posts: 16
Joined: Mon Dec 30, 2019 8:06 am

Re: How to get windows disk device instance path by python?

Post by zfm076 » Thu Jan 02, 2020 9:30 am

stijn wrote:
Thu Jan 02, 2020 8:28 am
You mean Python or MicroPython?

First case you can parse output of e.g.

Code: Select all

import os
os.popen('wmic diskdrive get PNPDeviceID').read() 
(your question doesn't specify which device, this will list all of them..)

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. 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
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: How to get windows disk device instance path by python?

Post by stijn » Thu Jan 02, 2020 1:03 pm

Something like this: https://superuser.com/questions/634842/ ... using-wmic or maybe using the Python psutil module

zfm076
Posts: 16
Joined: Mon Dec 30, 2019 8:06 am

Re: How to get windows disk device instance path by python?

Post by zfm076 » Tue Jan 07, 2020 10:30 am

stijn wrote:
Thu Jan 02, 2020 1:03 pm
Something like this: https://superuser.com/questions/634842/ ... using-wmic or maybe using the Python psutil module
Thank you very much.Helped me a lot. :D

Post Reply