Cross platform way to list disk drives on Linux, Windows and Mac using Python?

后端 未结 4 1575
名媛妹妹
名媛妹妹 2021-01-02 03:22

I am using Python2.6. I am trying to list the disk drives that a system may have.

On Windows, it may be something like C:/, D:/, E:/

4条回答
  •  Happy的楠姐
    2021-01-02 04:02

    There isn't really a unified naming scheme for Linux devices that guarantees you a formatable block device. There are conventions, but they can vary widely and I can call my thumb-drive /Thomas/O if I want and there is no cross-platform way in Python to know:

    1. That /Thomas/O corresponds to /dev/sdf1
    2. That /dev/sdf1 can have a FAT32 filesystem made on it
    3. That /dev/sdf is not preferred to /dev/sdf1

    I'm pretty sure that neither is there a cross-platform Python module which will allow you to determine that H:/ is formattable on a Windows system but that Z:/ is not.

    Each system will require its own specific checks and validations which you could best learn from studying open-source disk manipulation software.

提交回复
热议问题