使用 C# 获取磁盘空间的方法:

  1. public async static Task<int> GetFreeSpace()
  2. {
  3. StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  4. var properties = await localFolder.GetBasicPropertiesAsync();
  5. var filteredProperties = await properties.RetrievePropertiesAsync(new[] { "System.FreeSpace" });
  6. string freeSpace = filteredProperties["System.FreeSpace"].ToString();
  7. ulong size;
  8. int mb = ;
  9. if (ulong.TryParse(freeSpace, out size))
  10. mb = (int)(size / ( * ));
  11.  
  12. return mb;
  13. }

不过使用 C++ 比较麻烦,在网页上没有搜到,在微软 Github-(https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples) 上的 demo(FileAccess)中,找到了使用方式,改造了一下:

  1. auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
  2.  
  3. auto outputText = std::make_shared<String^>("Space: " + folder->Name);
  4.  
  5. // Get basic properties
  6. create_task(folder->GetBasicPropertiesAsync()).then([this, outputText](task<BasicProperties^> task)
  7. {
  8. try
  9. {
  10. BasicProperties^ basicProperties = task.get();
  11. *outputText += "\nFile size: " + basicProperties->Size.ToString() + " bytes";
  12. }
  13. catch (COMException^ ex)
  14. {
  15. //rootPage->HandleFileNotFoundException(ex);
  16. }
  17. }).then([this, folder]()
  18. {
  19. // Get extra properties
  20. auto propertiesName = ref new Vector<String^>();
  21. propertiesName->Append(L"System.FreeSpace");
  22. propertiesName->Append(L"System.Capacity");
  23.  
  24. return folder->Properties->RetrievePropertiesAsync(propertiesName);
  25. }).then([this, outputText](IMap<String^, Object^>^ extraProperties)
  26. {
  27. auto propValue = extraProperties->Lookup(L"System.FreeSpace");
  28. if (propValue != nullptr)
  29. {
  30. *outputText += "\n FreeSpace: " + propValue;
  31. }
  32.  
  33. auto propValue2 = extraProperties->Lookup(L"System.Capacity");
  34. if (propValue2 != nullptr)
  35. {
  36. *outputText += "\n Capacity: " + propValue2;
  37. }
  38. });

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. Mac Sublime Text 2 简单使用

    按 Ctrl+` 调出 console 粘贴以下代码到底部命令行并回车: import urllib2,os;pf='Package Control.sublime-package';ipp=subl ...

  2. Jni中C++和Java的参数传递 参数对照

    Jni中C++和Java的参数传递 如何使用JNI的一些基本方法和过程在网上多如牛毛,如果你对Jni不甚了解,不知道Jni是做什么的,如何建立一个基本的jni程序,或许可以参考下面下面这些文章:利用V ...

  3. 如何使用Unix/Linux grep命令——磨刀不误砍柴工系列

     http://man.linuxde.net/grep ---------------------------------------------------- 如何使用Unix/Linux gre ...

  4. Java中Properties类的操作

    知识学而不用,就等于没用,到真正用到的时候还得重新再学.最近在看几款开源模拟器的源码,里面涉及到了很多关于Properties类的引用,由于Java已经好久没用了,而这些模拟器大多用Java来写,外加 ...

  5. 在iOS7中修改状态栏字体的颜色

    http://www.2cto.com/kf/201408/324442.html 默认状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarS ...

  6. php substr中文乱码最有效到解决办法 转:http://blog.sina.com.cn/s/blog_49b531af0100esah.html

    (2009-07-29 12:29:38) 转载▼ 标签: php substr文乱码 网站开发 it   直接使用PHP函数substr截取中文字符可能会出现乱码,主要是substr可能硬生生的将一 ...

  7. Java字符串split函数的注意事项

    Java字符串的split方法可以分割字符串,但和其他语言不太一样,split方法的参数不是单个字符,而是正则表达式,如果输入了竖线(|)这样的字符作为分割字符串,会出现意想不到的结果, 如, Str ...

  8. lz4,pigz,gzip 3者比较

    一.压缩(1.1)使用gzip进行打包:# time tar -zcf tar1.tar binlog*real 0m48.497suser 0m38.371ssys 0m2.571s (1.2)使用 ...

  9. Git SSH Key 生成步骤

    it是分布式的代码管理工具,远程的代码管理是基于ssh的,所以要使用远程的git则需要ssh的配置. github的ssh配置如下: 一 . 设置git的user name和email: $ git ...

  10. 使用msgfmt编译多语言文件

    msgfmt --statistics --verbose -o django.mo django.po