zoukankan      html  css  js  c++  java
  • windows 之磁盘空间剩余空间监测

    监测软件当前目录的磁盘剩余量是否达到1GB

    bool SdLoginManager::checkDiskCapacity()
    {
      bool res = true;
      BOOL fResult;
      unsigned _int64 i64FreeBytesToCaller;
      unsigned _int64 i64TotalBytes;
      unsigned _int64 i64FreeBytes;
      int freespace = 0;
      float totalspace = 0;
      wchar_t szExePath[MAX_PATH] = { 0 };

      GetModuleFileNameW(NULL, szExePath, MAX_PATH);//获取当前进程所在路径截取磁盘路径即可
      wchar_t rootPaht[64] = {0};

      if (lstrlen(szExePath) <= 0)
      {
        SdLog("get the curentdir with error %d",GetLastError());
        return res;
      }

      wcsncpy(rootPaht, szExePath, 3);

      fResult = GetDiskFreeSpaceEx(rootPaht,                //获取磁盘剩余空间大小,总大小.
                    (PULARGE_INTEGER)&i64FreeBytesToCaller,
                    (PULARGE_INTEGER)&i64TotalBytes,
                    (PULARGE_INTEGER)&i64FreeBytes);

      if (fResult)
      {
        totalspace = (float)i64TotalBytes / 1024 / 1024 / 1024;
        freespace = (float)i64FreeBytes / 1024 / 1024 / 1024;
      }
      if (!freespace)
      {
        res = false;
      }

      return res;
     }

    以上结合cmd:>  fsutil file createnew E: ext.txt  1024000000  

    上述命令生成1GB txt具体大小自己定义,然后进行测试,别生成在C盘即可.

    具体api详情转ms手册:

    https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew

    https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexa

  • 相关阅读:
    c++ 中 pair 的 使用方法
    初窥c++11:lambda函数及其用法
    HDU2089-不要62
    算法训练 K好数
    点评删除和编辑
    事务
    SQL Function 自定义函数
    常用CSS实例
    分页显示数据
    开发教程指南
  • 原文地址:https://www.cnblogs.com/liuruoqian/p/13023943.html
Copyright © 2011-2022 走看看