【问题标题】:UWP How to get StorageDevice freespace and capacity?UWP 如何获取 StorageDevice 可用空间和容量?
【发布时间】:2018-09-17 12:50:15
【问题描述】:

在我的 UWP 应用程序中,我使用此构造来获取所有 StorageDevices 的列表:

List<StorageFolder> list = new List<StorageFolder>();
var selector = Windows.Devices.Portable.StorageDevice.GetDeviceSelector();

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);

foreach (Windows.Devices.Enumeration.DeviceInformation device in devices)
    {
        // Get device root folder
        StorageFolder rootFolder = Windows.Devices.Portable.StorageDevice.FromId(device.Id);
        list.Add(rootFolder);
    }

RemovableItems.DataContext = new RemovableStorageViewModel(list);

如何获取此设备的可用空间和容量? 我尝试从文件夹道具rootFolder.Properties.RetrievePropertiesAsync(new List&lt;string&gt;()) 中获取它,但是这个道具不见了。

更新:

可用的道具值:

可用的道具键:

为什么缺少可用空间和容量?

【问题讨论】:

  • This answer 可能帮助不大。
  • @Romasz 不。我知道如何从标准文件夹中获取此道具,但在我的情况下它不起作用。

标签: c# win-universal-app


【解决方案1】:

您是否尝试查询System.FreeSpaceSystem.Capacity 属性(有关可用属性https://msdn.microsoft.com/en-us/library/windows/desktop/bb760719%28v=vs.85%29.aspx 的更多信息)

用法:

var retrivedProperties = await rootFolder.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
var freeSpace = (UInt64)retrivedProperties["System.FreeSpace"];

【讨论】:

  • 是的,我试试。我无法获得 System.FreeSpaceSystem.Capacity 道具,因为它们不见了。
  • retrivedProperties["System.FreeSpace"] 找不到。
【解决方案2】:

我尝试过做同样的事情,但没有成功。 Microsoft 出于某种原因省略了这些属性。希望下一次 SDK 更新能够解决这个问题。

【讨论】:

    【解决方案3】:

    从 Windows 10 版本 1803(10.0:Build 17134)开始,我能够检索 一些 驱动器的“System.FreeSpace”和“System.Capacity”属性,使用 thang2410199 的答案

    您可以在我对这个问题的回答中看到一个代码示例:Error while accessing AvailableFreeSpace/TotalSize in DriveInfo in UWP

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-22
      • 2020-05-03
      • 2013-12-05
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      相关资源
      最近更新 更多