16、C++获取磁盘空间的方法
使用 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++获取磁盘空间的方法的更多相关文章
- 【翻译自mos文章】回收 asm磁盘空间的方法
回收 asm磁盘空间的方法 參考原文: How To Reclaim Asm Disk Space? (Doc ID 351866.1) 适用于: Oracle Database - Enterpri ...
- mongodb拷贝数据库copyDatabase()。实现释放磁盘空间的方法。
下面我们一起来看看关于mongodb拷贝数据库copyDatabase().实现释放磁盘空间的方法,希望文章对各位同学会有所帮助. db.copyDatabase("from",& ...
- 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 ...
- LINUX下添加磁盘空间的方法详解
给Linux系统添加磁盘空间在工作会经常遇到. 在添加第二块磁盘一般系统默认为hdb(IDE硬盘)sdb(SCSI 硬盘),以hdb为例. linux-isep:~ # fdisk /dev/hdb ...
- JAVA获取磁盘空间
需要把磁盘空间显示在页面上,这样就不用去服务器查看了,方便 两个办法 File file = new File("D:"); long totalSpace = file.getT ...
- VMware vSphere Client下增加虚拟机磁盘空间的方法
随着系统运维时间的增长,磁盘就日益的损耗,如果遇到虚拟机报磁盘空间不足怎么办?还好,我们可以通过磁盘阵列增加磁盘空间,然后扩容到虚拟机中去. 对于linux虚拟机磁盘扩容的方案有两种,一种就是原有的实 ...
- linux查看系统未被挂载的磁盘空间的方法
原文URL:https://www.cnblogs.com/lemon-flm/p/7597403.html 解决AWS 挂载.解决挂载完重启就消失等问题 linux上的盘和window的有区别,磁盘 ...
- C# 获取磁盘空间大小的方法
方法一:利用System.IO.DriveInfo.GetDrives方法来获取 /// /// 获取指定驱动器的空间总大小(单位为B) /// /// 只需输入代表驱动器的字母即可 (大写) /// ...
- Delphi实现获取磁盘空间大小的方法
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...
随机推荐
- ajax原理,验证码生成原理
什么是ajax AJAX:”Asynchronous JavaScript and XML” 中文意思:异步JavaScript和XML 指一种创建交互式网页应用的网页开发技术. 不是指一种单一的 ...
- GDB中应该知道的几个调试方法 来自陈皓
GDB中应该知道的几个调试方法 2011年2月10日陈皓发表评论阅读评论62,325 人阅读 七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询 ...
- CF440C
C. One-Based Arithmetic time limit per test 0.5 seconds memory limit per test 256 megabytes input st ...
- Array和ArrayList互相转换
class Order{ public string orderId; public string orderName; public decimal orderPrice; } public cla ...
- NGUI之scroll view制作,以及踩的坑总结
http://blog.csdn.net/monzart7an/article/details/23878505 链接: http://game.ceeger.com/forum/read.php?t ...
- [codeforces 516]A. Drazil and Factorial
[codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define ...
- Access数据库之偏移注入
/*转载请注明出处:珍惜少年时*/ 偏移注入主要是针对知道表,但是不知道字段的. 这里我已经知道了表明是:sys_admin 可以使用: select exists(selct * from sys_ ...
- Android音频播放实例
MediaPlayer: 此类适合播放较大文件,此类文件应该存储在SD卡上,而不是在资源文件里,还有此类每次只能播放一个音频文件. 1.从资源文件中播放 MediaPlayer player = ne ...
- HDOJ 1233
还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Centos6.7安装Apache2.4+Mysql5.6+Apache2.4
首先说下思路,因为一开始系统上已经跑了一套完成的 PHP 环境,那时候都是快速自动安装的,如果是跑一些5.3以下版本的话,很简单,几个指令,10分钟搞定了. 但现在要升级,彻底一点的话,唯有推倒重来了 ...