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, ...
随机推荐
- Common Pitfalls In Machine Learning Projects
Common Pitfalls In Machine Learning Projects In a recent presentation, Ben Hamner described the comm ...
- WAF与IPS的区别总结
谁是最佳选择? Web应用防护无疑是一个热门话题.由于技术的发展成熟和人们对便利性的期望越来越高,Web应用成为主流的业务系统载体.在Web上“安家”的关键业务系统中蕴藏的数据价值引起攻击者的青睐,网 ...
- Shell脚本获得变量值作为新变量一部分的值
最近使用shell写一个发布脚本时,由于shell编程是边学便用的缘故,经验不足,中间遇到一个问题,一个变量的值作为一个新变量的一部分,而我要根据变量获得新变量的值,以前没有遇到过.网络搜索一番,最后 ...
- 【iOS】app的生命周期
对于iOS应用程序,关键的是要知道你的应用程序是否正在前台或后台运行.由于系统资源在iOS设备上较为有限,一个应用程序必须在后台与前台有不同的行为.操作系统也会限制你的应用程序在后台的运行,以提高电池 ...
- ASP.NET使用FileUpload上传文件
前台代码: <asp:FileUpload ID="fuKeleyi" runat="server" /> <asp:Button ID=&q ...
- Zhulina 的高分子刷理论
高分子刷的解析平均场理论有两种表述方式.一个是MWC理论(Macromolecules 1988, 21, 2610-2619),另外一个就是Zhulina和Birshtein这两位俄罗斯老太太的理论 ...
- 杭赛.Triangle(数学推导)
Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- sql分组取第一条数据
sq分组取第一条数据的一个方法: select * from ( select row_number() over(partition by ID order by ID) as rownum , * ...
- 暑假热身 D. 条形码设计
校ACM队准备筹划向学校批请一个专用机房.但是为了防止它变成公用机房,FL建议采用刷卡进入的办法,她设计了一种条形码,每人都对应一个.这种大小为2*n的条形码由以下三种元素构成:1*2.2*1.2*2 ...
- MySQL 索引详解大全
什么是索引? 1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引,会保存在额外的文件中. 2. 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结 ...