import ctypes
import os
import platform
import sys

def get_free_space_mb(folder):
    """ Return folder/drive free space (in bytes)
    """
    if platform.system() == 'Windows':
        free_bytes = ctypes.c_ulonglong(0)
        ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
        return free_bytes.value/1024/1024/1024
    else:
        st = os.statvfs(folder)
        return st.f_bavail * st.f_frsize/1024/1024

print(get_free_space_mb('C:\\'),'GB')
import win32com.client as com

def TotalSize(drive):
    """ Return the TotalSize of a shared drive [GB]"""
    try:
        fso = com.Dispatch("Scripting.FileSystemObject")
        drv = fso.GetDrive(drive)
        return drv.TotalSize/2**30
    except:
        return 0

def FreeSpace(drive):
    """ Return the FreeSpace of a shared drive [GB]"""
    try:
        fso = com.Dispatch("Scripting.FileSystemObject")
        drv = fso.GetDrive(drive)
        return drv.FreeSpace/2**30
    except:
        return 0

workstations = ['dolphins']
print ('Hard drive sizes:')
for compName in workstations:
    drive = '\\\\' + compName + '\\c$'
    print ('*************************************************\n')
    print (compName)
    print ('TotalSize of %s = %f GB' % (drive, TotalSize(drive)))
    print ('FreeSpace on %s = %f GB' % (drive, FreeSpace(drive)))
    print ('*************************************************\n')

两种方法,获取磁盘剩余空间--PYTHON的更多相关文章

  1. Linux C++获取磁盘剩余空间和可用空间

    完整源码 #include <sys/statfs.h> #include <string> #include <iostream> #include <li ...

  2. C# 获取磁盘剩余空间

    drive.TotalFreeSpace单位为bit,根据需要除以1024 drive同时可以可以获取磁盘分区容量等 //单位MB public static long GetHardDiskSpac ...

  3. 两种方法获取MyBatis刚刚插入的id

    主要就是在xml文件中的写法,其他省略 方法一: <insert id="insert" parameterType="com.xxx.xxxx.pojo.User ...

  4. 两种方法获取shadow ssdt

    ULONG GetShadowSsdtCurrentAddresses( PSSDT_ADDRESS   AddressInfo, PULONG          Length ) { PSYSTEM ...

  5. Delphi使用两种不同方法获取系统端口信息--(装载)

    Delphi使用两种方法获取windows系统的端口,还可测试发送消息,点击获取端口信息后,可依次得到如下信息:DCB结构大小.波特率大小.XON的临界值.XOFF的临界值.字符位数.奇偶检验位.停止 ...

  6. 用easyui从servlet传递json数据到前端页面的两种方法

    用easyui从servlet传递json数据到前端页面的两种方法 两种方法获取的数据在servlet层传递的方法相同,下面为Servlet中代码,以查询表中所有信息为例. //重写doGet方法 p ...

  7. linux系统的磁盘空间限制的两种方法

    最近在搞VPS,要用到磁盘的限额,在网上找了一些相关的资料,总结起来,有两个方法能实现,一是用quota,另外一种是限制目录大小,下面我就将这两种方法写出来,与大家一起分享! 首先我们来看第一种方法, ...

  8. windows下获取IP地址的两种方法

    windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...

  9. python中执行shell的两种方法总结

    这篇文章主要介绍了python中执行shell的两种方法,有两种方法可以在Python中执行SHELL程序,方法一是使用Python的commands包,方法二则是使用subprocess包,这两个包 ...

随机推荐

  1. mysql 中间件 分析

    360的Atlas 1.读写分离 2.从库负载均衡 3.IP过滤 4.自动分表 5.DBA可平滑上下线DB 6.自动摘除宕机的DB altas 在10000/s的请求量级应该是毫无问题的 https: ...

  2. JavaScript无限极菜单

    <!DOCTYPE html> <html> <head> <title> New Document </title> <meta c ...

  3. Ubuntu server搭建vsftpd小记

    Ubuntu server中搭建vsftpd小记 <h1> 在Ubuntu server中安装vsftpd</h1> sudo apt-get install vsftpd & ...

  4. 第九篇:web之前端之web上传文件的方式

    前端之web上传文件的方式   前端之web上传文件的方式 本节内容 web上传文件方式介绍 form上传文件 原生js实现ajax上传文件 jquery实现ajax上传文件 form+iframe构 ...

  5. ibatis配置xml文件中CDATA的用法

    ibatis作为一种半自动化的OR Mapping工具,其灵活性日益体现出来,越来越多的人都倾向于在项目中使用.由于Sql中经常有与xml规范相冲突的字符对xml映射文件的合法性造成影响.许多人都知道 ...

  6. webrtc学习——mediaStream和MediaStreamTrack

    This is an experimental technologyBecause this technology's specification has not stabilized, check ...

  7. angularjs + springmvc 上传和下载

    jsp: <form ng-submit="uploadFile()" class="form-horizontal" enctype="mul ...

  8. 500 OOPS: cannot change directory:/home/test

    问题:  以root   从远程客户端 登录 FTP  一直密码错误.  发现不能以root 登录, 需要创建其它的用户. 创建一个test 用户后(如下): useradd test; passwd ...

  9. mysql 根据某个字段将多条记录的某个字段拼接成一个字段

    未合并情况 SELECT a.id, b.name AS "role" FROM sys_user a INNER JOIN sys_user_role c ON a.id=c.u ...

  10. fastjson的坑 com.alibaba.fastjson.JSONObject cannot be cast to xxx

    解析json对象时,使用了new TypeReference()对象 fastjson会对解析的对象类型进行缓存   new TypeReference<ResultData>(){}   ...