在 Windows 10 IoT 中检测可用的存储文件夹 space?

Detect available storagefolder space in Windows 10 IoT?

有没有办法检测存储文件夹中可用 space 的数量?我正在使用下面的代码将文本文件写入目录,但想知道有多少 space 可用。我的应用程序会将音频文件写入目录,并希望能够检测到可用存储 space。谢谢

var storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data", CreationCollisionOption.OpenIfExists);
var storageFile = await storageFolder.CreateFileAsync("Test.txt", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

您可以使用 StorageFolder.Properties.RetrievePropertiesAsync() api.

我用下面的代码测试过:

        //Get the available space
        var storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data", CreationCollisionOption.OpenIfExists);
        var result = await storageFolder.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
        var freeSpace = result["System.FreeSpace"];

        //Do something to take up some space of "Data" folder
        byte[] data = new byte[1024000];
        var storageFile = await storageFolder.CreateFileAsync("Test.txt", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
        await FileIO.WriteBytesAsync(storageFile,data);

        //Get the available space
        var result2 = await storageFolder.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
        var freeSpace2 = result2["System.FreeSpace"];