UWP如何获得存储设备的可用空间和容量?

问题描述 投票:0回答:3

在我的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<string>())得到它,但这个道具缺失。

更新:

可用的道具价值:Available props values

可用的道具键:Available props keys

为什么自由空间和容量缺失?

c# win-universal-app
3个回答
0
投票

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


0
投票

您是否尝试查询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"];

0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.