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, ...
随机推荐
- mysql 外键(FOREIGN KEY)
最近有开始做一个实验室管理系统,因为分了几个表进行存储·所以要维护表间的关联··研究了一下MySQL的外键. (1)只有InnoDB类型的表才可以使用外键,mysql默认是MyISAM,这种类型不支持 ...
- Windows 下的.NET+ Memcached安装
转载请标明出处: http://www.yaosansi.com/ 原文:http://www.yaosansi.com/post/1396.html Memcached官方:http://danga ...
- Java JNI 编程进阶 实例+c++数据类型与jni数据类型转换
原文:http://www.iteye.com/topic/295776 JNI一直以来都很少去关注,但却是我心中的一个结,最近这几天刚好手头有点时间,因此抽空看了一下这方面的东西,整理了一份文档,J ...
- commons-logging和Log4j 日志管理/log4j.properties配置详解
commons-logging和Log4j 日志管理 (zz) 什么要用日志(Log)? 这个……就不必说了吧. 为什么不用System.out.println()? 功能太弱:不易于控制.如果暂时不 ...
- ashx 获取ajax Post到后台json数据
前台页面代码: var json = [{ "Name": "Pavan Kumar Pabothu", "Age": 27, " ...
- c#接口和抽象类对比学习
什么是接口? 接口就是一种规范,协议(*),约定好遵守某种规范就可以写通用的代码. 定义了一组具有各种功能的方法.接口描述的是一种能力,具有这种能力的事物可以没任何关系.比如: public inte ...
- javascript判断上传文件大小
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- glutBitmapCharacter及glBitmap在ATI显卡下无法正常显示的原因初探
最近家里台式机的老显卡烧了,所以更换了ATI的HD6450显卡,却发现glutBitmapCharacter及glBitmap都无法正常显示字符,nviDIA和intel的显卡则一切正常. 发邮件咨询 ...
- unity3d的四元数 Quaternion
原地址:http://www.cnblogs.com/88999660/archive/2013/04/02/2995074.html 今天准备学习和研究下unity3d的四元数 Quaternion ...
- [BZOJ2724][Violet 6]蒲公英
[BZOJ2724][Violet 6]蒲公英 试题描述 输入 修正一下 l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1 输出 输入示 ...