简体   繁体   English

使用python查找USB大容量存储设备的卷标

[英]Finding Volume Label of a usb mass storage device using python

Could someone please tell me how I could obtain a usb mass storage device's volume label(the name displayed in the explorer, not the device name::/dev/sdX) using python? 有人可以告诉我如何使用python获取USB大容量存储设备的卷标(资源管理器中显示的名称,而不是设备名称::: / dev / sdX)吗? HAL has deprecated so please don't suggest it as an option. HAL已弃用,因此请不要建议使用它。

EDIT: Is there a way to do it using pyudev or pyusb?? 编辑:有没有办法使用pyudev或pyusb?

If you don't want to use HAL you could do it by calling a subprocess . 如果您不想使用HAL,则可以通过调用子进程来实现

import subprocess

mounts = {}

for line in subprocess.check_output(['mount', '-l']).split('\n'):
    parts = line.split(' ')
    if len(parts) > 2:
        mounts[parts[2]] = parts[0]

print mounts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM