zoukankan      html  css  js  c++  java
  • 获取磁盘的 总容量,空余容量,已用容量 【windows】

    使用windows api

    输入:盘符字符串

    输出:磁盘容量

    float get_disk_spaces(const char drive_letter, float & total_space, float & used_space)
    {
        BOOL fResult;
        unsigned _int64 i64FreeBytesToCaller;
        unsigned _int64 i64TotalBytes;
        unsigned _int64 i64FreeBytes;
        char dir[4] = { drive_letter, ':', '\', ''};
        fResult = GetDiskFreeSpaceExA(
            dir,
            (PULARGE_INTEGER)&i64FreeBytesToCaller,
            (PULARGE_INTEGER)&i64TotalBytes,
            (PULARGE_INTEGER)&i64FreeBytes);
        if (fResult)
        {
            /*QMessageBox::about(NULL, "Information",
                ("Get disk space " + QString(dir) + QString::number(i64TotalBytes)));*/
            total_space = (float)i64TotalBytes;
            used_space = (float)(i64TotalBytes - i64FreeBytes);
            return (float)i64TotalBytes;
        }
        else
            QMessageBox::about(NULL, "Information",
                ("Failed to get disk space " + QString(dir)));
     
        return -1;
    }

    注意其中的字符数组 dir 一定要以''结尾,否则程序时好时坏,因为有时dir末尾正好是0,而有时不是。

  • 相关阅读:
    jmeter Transaction Controller、Throughput Controller 控制器
    图书系统的简易代码
    模板简单梳理
    自制过滤器
    自制URL转换器
    URL简单梳理
    window下的Django入门
    十一、常用内建模块
    九、进程与线程
    八、错误、调试与测试
  • 原文地址:https://www.cnblogs.com/liujx2019/p/10309860.html
Copyright © 2011-2022 走看看