如何获取目录或驱动器的文件系统? [英] How to get the filesystem of a directory or drive?

查看:74
本文介绍了如何获取目录或驱动器的文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定给定路径或驱动器是否在Python中格式化为EXT4,EXT3,EXT2,FAT32,NTFS或类似的格式?

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

推荐答案

psutil 是跨平台软件包,可以识别分区类型:

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')]

警告:在linux上,fstype可能报告为ext4ntfs,但是在Windows上,fstype被限制为"removable", "fixed", "remote", "cdrom", "unmounted" or "ramdisk".

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".

这篇关于如何获取目录或驱动器的文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆