检测Windows 10 IoT中的可用存储文件夹空间?

时间:2017-01-24 23:58:28

标签: iot windows-10-iot-core windowsiot

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

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

1 个答案:

答案 0 :(得分:1)

您可以使用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"];