How to get the filesystem of a directory or drive?

前端 未结 1 1572
太阳男子
太阳男子 2021-01-06 13:49

How do I determine if a given path or drive is formatted to EXT4, EXT3, EXT2, FAT32, NTFS or some such, in Python?

相关标签:
1条回答
  • 2021-01-06 14:04

    psutil is a cross-platform package which can identify partition types:

    >>> psutil.disk_partitions()
    [sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
     sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext4', opts='rw')]
    

    Warning: On linux, the fstype may be reported as ext4 or ntfs, but on Windows, the fstype is limited to "removable", "fixed", "remote", "cdrom", "unmounted" or "ramdisk".

    0 讨论(0)
提交回复
热议问题