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, ...
随机推荐
- Mac Sublime Text 2 简单使用
按 Ctrl+` 调出 console 粘贴以下代码到底部命令行并回车: import urllib2,os;pf='Package Control.sublime-package';ipp=subl ...
- Jni中C++和Java的参数传递 参数对照
Jni中C++和Java的参数传递 如何使用JNI的一些基本方法和过程在网上多如牛毛,如果你对Jni不甚了解,不知道Jni是做什么的,如何建立一个基本的jni程序,或许可以参考下面下面这些文章:利用V ...
- 如何使用Unix/Linux grep命令——磨刀不误砍柴工系列
http://man.linuxde.net/grep ---------------------------------------------------- 如何使用Unix/Linux gre ...
- Java中Properties类的操作
知识学而不用,就等于没用,到真正用到的时候还得重新再学.最近在看几款开源模拟器的源码,里面涉及到了很多关于Properties类的引用,由于Java已经好久没用了,而这些模拟器大多用Java来写,外加 ...
- 在iOS7中修改状态栏字体的颜色
http://www.2cto.com/kf/201408/324442.html 默认状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarS ...
- php substr中文乱码最有效到解决办法 转:http://blog.sina.com.cn/s/blog_49b531af0100esah.html
(2009-07-29 12:29:38) 转载▼ 标签: php substr文乱码 网站开发 it 直接使用PHP函数substr截取中文字符可能会出现乱码,主要是substr可能硬生生的将一 ...
- Java字符串split函数的注意事项
Java字符串的split方法可以分割字符串,但和其他语言不太一样,split方法的参数不是单个字符,而是正则表达式,如果输入了竖线(|)这样的字符作为分割字符串,会出现意想不到的结果, 如, Str ...
- lz4,pigz,gzip 3者比较
一.压缩(1.1)使用gzip进行打包:# time tar -zcf tar1.tar binlog*real 0m48.497suser 0m38.371ssys 0m2.571s (1.2)使用 ...
- Git SSH Key 生成步骤
it是分布式的代码管理工具,远程的代码管理是基于ssh的,所以要使用远程的git则需要ssh的配置. github的ssh配置如下: 一 . 设置git的user name和email: $ git ...
- 使用msgfmt编译多语言文件
msgfmt --statistics --verbose -o django.mo django.po