使用 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. 织梦DedeCMS删除所有栏目或文章后,新建ID不从1开始的解决方法

    这个修改方法很简单,从模板无忧那里找到的,只需要在后台系统-SQL命令行工具里面运行以下语句即可,不用采用笨方法重新安装织梦CMS了. 删除所有栏目,新建ID从1开始: ALTER TABLE `de ...

  2. 锋利的jQuery-4--trigger()和triggerHandler()

    trigger()方法触发事件后,会执行浏览器默认操作. $("input").trigger("focus") 以上的代码不仅会执行input绑定的focus ...

  3. import numpy 和 from numpy import * 的区别

    对于 import xxx 使用函数的方法为 x'x'x.Afunc 而对于 from xxx import * 调用函数的方法为 Afunc

  4. IIS负载均衡-Application Request Route详解第一篇: ARR介绍(转载)

    IIS负载均衡-Application Request Route详解第一篇: ARR介绍 说到负载均衡,相信大家已经不再陌生了,本系列主要介绍在IIS中可以采用的负载均衡的软件:微软的Applica ...

  5. heap和stack有什么区别

    1.heap是堆,stack是栈. 2.stack的空间由操作系统自动分配和释放,heap的空间是手动申请和释放的,heap常用new关键字来分配. 3.stack空间有限,heap的空间是很大的自由 ...

  6. web前端跨域方案

    ajax跨域请求   qzfl实现 跨子域的xhr 原生xhr不支持跨域,通过iframe+proxy.html达到跨子域 假如A页面要请求B页面,A.B跨子域.A创建指向B的proxy页的ifram ...

  7. Swift Tour 随笔总结 (2)

    Type Aliases typealias AudioSample = UInt16 Booleans 非boolean值不会被替代为bool,例如: let i = 1 if i { // thi ...

  8. Forth scrum meeting - 2015/10/29

    今天下午,我们终于要到了MOOC服务器端开发人员的联系方式,于是我们小组派了三名同学去实验室与他们进行了交流,并咨询了他们一些关于API接口的问题.他们也对我们这个客户端的开发提出了一些建议. 开发团 ...

  9. Linux中启动和停止jar包的运行

    脚本一: startTest.sh内容如下: #!/bin/sh java -jar Test.jar &       #注意:必须有&让其后台执行,否则没有pid生成 echo $! ...

  10. Python win7下 django-admin.py startproject mysite命令没有创建mysite?

    解决方案 解决:这个命令在XP下正常(我没试过),我用的win7,无法创建.这属于django的一个bug. 方法是:修改注册表中 HKEY_CLASSES_ROOT/Applications/pyt ...