使用 C# 获取磁盘空间的方法:

 public async static Task<int> GetFreeSpace()
{
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
var properties = await localFolder.GetBasicPropertiesAsync();
var filteredProperties = await properties.RetrievePropertiesAsync(new[] { "System.FreeSpace" });
string freeSpace = filteredProperties["System.FreeSpace"].ToString();
ulong size;
int mb = ;
if (ulong.TryParse(freeSpace, out size))
mb = (int)(size / ( * )); return mb;
}

不过使用 C++ 比较麻烦,在网页上没有搜到,在微软 Github-(https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples) 上的 demo(FileAccess)中,找到了使用方式,改造了一下:

auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;

auto outputText = std::make_shared<String^>("Space: " + folder->Name);

// Get basic properties
create_task(folder->GetBasicPropertiesAsync()).then([this, outputText](task<BasicProperties^> task)
{
try
{
BasicProperties^ basicProperties = task.get();
*outputText += "\nFile size: " + basicProperties->Size.ToString() + " bytes";
}
catch (COMException^ ex)
{
//rootPage->HandleFileNotFoundException(ex);
}
}).then([this, folder]()
{
// Get extra properties
auto propertiesName = ref new Vector<String^>();
propertiesName->Append(L"System.FreeSpace");
propertiesName->Append(L"System.Capacity"); return folder->Properties->RetrievePropertiesAsync(propertiesName);
}).then([this, outputText](IMap<String^, Object^>^ extraProperties)
{
auto propValue = extraProperties->Lookup(L"System.FreeSpace");
if (propValue != nullptr)
{
*outputText += "\n FreeSpace: " + propValue;
} auto propValue2 = extraProperties->Lookup(L"System.Capacity");
if (propValue2 != nullptr)
{
*outputText += "\n Capacity: " + propValue2;
}
});

16、C++获取磁盘空间的方法的更多相关文章

  1. 【翻译自mos文章】回收 asm磁盘空间的方法

    回收 asm磁盘空间的方法 參考原文: How To Reclaim Asm Disk Space? (Doc ID 351866.1) 适用于: Oracle Database - Enterpri ...

  2. mongodb拷贝数据库copyDatabase()。实现释放磁盘空间的方法。

    下面我们一起来看看关于mongodb拷贝数据库copyDatabase().实现释放磁盘空间的方法,希望文章对各位同学会有所帮助. db.copyDatabase("from",& ...

  3. How to get the free disk space in PostgreSQL (PostgreSQL获取磁盘空间)

    Get the current free disk space in PostgreSQL PostgreSQL获取磁盘空间 from eshizhan Here has a simple way t ...

  4. LINUX下添加磁盘空间的方法详解

    给Linux系统添加磁盘空间在工作会经常遇到. 在添加第二块磁盘一般系统默认为hdb(IDE硬盘)sdb(SCSI 硬盘),以hdb为例. linux-isep:~ # fdisk /dev/hdb ...

  5. JAVA获取磁盘空间

    需要把磁盘空间显示在页面上,这样就不用去服务器查看了,方便 两个办法 File file = new File("D:"); long totalSpace = file.getT ...

  6. VMware vSphere Client下增加虚拟机磁盘空间的方法

    随着系统运维时间的增长,磁盘就日益的损耗,如果遇到虚拟机报磁盘空间不足怎么办?还好,我们可以通过磁盘阵列增加磁盘空间,然后扩容到虚拟机中去. 对于linux虚拟机磁盘扩容的方案有两种,一种就是原有的实 ...

  7. linux查看系统未被挂载的磁盘空间的方法

    原文URL:https://www.cnblogs.com/lemon-flm/p/7597403.html 解决AWS 挂载.解决挂载完重启就消失等问题 linux上的盘和window的有区别,磁盘 ...

  8. C# 获取磁盘空间大小的方法

    方法一:利用System.IO.DriveInfo.GetDrives方法来获取 /// /// 获取指定驱动器的空间总大小(单位为B) /// /// 只需输入代表驱动器的字母即可 (大写) /// ...

  9. Delphi实现获取磁盘空间大小的方法

    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...

随机推荐

  1. python之字符聊天小工具

    server side: # coding: gb2312#socket server端#获取socket构造及常量from socket import *#''代表服务器为localhostmyHo ...

  2. ssh中getHibernateTemplate()的方法

    spring接着又把业务类中的查询也封装成了find() //用来实现分页 /*HibernateTemplate ht=this.getHibernateTemplate(); DetachedCr ...

  3. JNI环境变量——JNIEnv*的使用 &&配置jd环境变量

      如果没有配置环境变量,先配置环境变量,如下: 1.右键我的电脑——高级——环境变量——下面的系统变量 2.选择[新建系统变量]--弹出“新建系统变量”对话框,在“变量名”文本框输入“JAVA_HO ...

  4. Socket网络编程(2)--服务端实现

    中秋了,首先祝大家中秋快乐,闲着无事在家整一个socket的聊天程序,有点仿QQ界面,就是瞎折腾,不知道最后是不是能将所有功能实现. 如果你对socket不了解,请看这篇文章:http://www.c ...

  5. GCC 编译详解

    GNU CC(简称为Gcc)是GNU项目中符合ANSI C标准的编译系统,能够编译用C.C++和Object C等语言编写的程序.Gcc不仅功能强大,而且可以编译如C.C++.Object C.Jav ...

  6. NAT/PAT

    NAT/PAT 编辑 NAT就是网络地址翻译的英文缩写,在路由器上配置NAT服务,可提供公司内100~200人同时上网的服务.不需要Proxy Server,所有的服务都可顺利使用(除Netmeeti ...

  7. windows下安装redis以及简单的事例

    1.安装服务端下载地址:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload我下载了一个 redis-2.0.0服务器包,解压 ...

  8. 错误 1 未知的服务器标记“asp:ScriptManager”。

    如题 ... 解决方案 :将 <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=ne ...

  9. SQL例题合集

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. Select sname,ssex,class from student; 2. 查询教师所有的单位即不重复的Depart ...

  10. 网站程序版本号信息也可能造成bd快照严重滞后

    在a5上看到一篇“破解阿里云论坛的快照时间迷局 或涉足所有phpwind论坛”的文章,里面说到pw的一个版本信息导致了快照滞后的问题,这再次验证了之前那篇文章“时间戳造成快照滞后”的准确性. 如下图所 ...