python 除了wmi,是否还有其它方式可以获取windows磁盘空间
展开全部
本文实例讲述了和兄升python使用wmi模块获取windows下硬盘信唤老息的方法。分享给大家供大家参考。具体实现方法如下:
# -*- coding: utf-8 -*-
#import
########################################################################
import os, sys
import time
import wmi
########################################################################
#function
########################################################################
def get_disk_info():
"""
获取物理磁盘信息。
"""
tmplist = []
c = wmi.WMI ()
for physical_disk in c.Win32_DiskDrive ():
tmpdict = {}
tmpdict["Caption"] = physical_disk.Caption
tmpdict["Size"] = long(physical_disk.Size)/1024/1024/1024
tmplist.append(tmpdict)
return tmplist
def get_fs_info() :
"""
获取文件系统信息。
包含分区的大小、已用量、可用量、使用率、挂载点信息。
"""
tmplist = []
c = wmi.WMI ()
for physical_disk in c.Win32_DiskDrive ():
for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
tmpdict = {}
tmpdict["Caption"] = logical_disk.Caption
tmpdict["DiskTotal"] = long(logical_disk.Size)/1024/1024/尘宏1024
tmpdict["UseSpace"] = (long(logical_disk.Size)-long(logical_disk.FreeSpace))/1024/1024/1024
tmpdict["FreeSpace"] = long(logical_disk.FreeSpace)/1024/1024/1024
tmpdict["Percent"] = int(100.0*(long(logical_disk.Size)-long(logical_disk.FreeSpace))/long(logical_disk.Size))
tmplist.append(tmpdict)
return tmplist
if __name__ == "__main__":
disk = get_disk_info()
print disk
print '--------------------------------------'
fs = get_fs_info()
print fs
希望本文所述对大家的Python程序设计有所帮助。
# -*- coding: utf-8 -*-
#import
########################################################################
import os, sys
import time
import wmi
########################################################################
#function
########################################################################
def get_disk_info():
"""
获取物理磁盘信息。
"""
tmplist = []
c = wmi.WMI ()
for physical_disk in c.Win32_DiskDrive ():
tmpdict = {}
tmpdict["Caption"] = physical_disk.Caption
tmpdict["Size"] = long(physical_disk.Size)/1024/1024/1024
tmplist.append(tmpdict)
return tmplist
def get_fs_info() :
"""
获取文件系统信息。
包含分区的大小、已用量、可用量、使用率、挂载点信息。
"""
tmplist = []
c = wmi.WMI ()
for physical_disk in c.Win32_DiskDrive ():
for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
tmpdict = {}
tmpdict["Caption"] = logical_disk.Caption
tmpdict["DiskTotal"] = long(logical_disk.Size)/1024/1024/尘宏1024
tmpdict["UseSpace"] = (long(logical_disk.Size)-long(logical_disk.FreeSpace))/1024/1024/1024
tmpdict["FreeSpace"] = long(logical_disk.FreeSpace)/1024/1024/1024
tmpdict["Percent"] = int(100.0*(long(logical_disk.Size)-long(logical_disk.FreeSpace))/long(logical_disk.Size))
tmplist.append(tmpdict)
return tmplist
if __name__ == "__main__":
disk = get_disk_info()
print disk
print '--------------------------------------'
fs = get_fs_info()
print fs
希望本文所述对大家的Python程序设计有所帮助。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询