0

I have a USB thumb-drive connected to my raspberry pi 3. I'd need to find out how to check for the available disk space to be printed on a textblock. I couldn't find any example for UWP application. What I found was GetDiskFreeSpaceEx function and Is there a method available for UWP apps to get available disk space Is there any example I could refer to? Thanks.

Updated: I have tried [Get available disk free space for a given path on Windows [duplicate]] .. Couldn't get it to work too..

mylim
  • 313
  • 4
  • 16

1 Answers1

1

You can use StorageFolder.Properties.RetrievePropertiesAsync() API to get the free space size of USB storage.I tested with the following pieces of code:

            var removableDevices = KnownFolders.RemovableDevices;
            var externalDevices = await removableDevices.GetFoldersAsync();
            var usbDriver = externalDevices.FirstOrDefault();

            var allProperties = usbDriver.Properties;
            IEnumerable<string> propertiesToRetrieve = new List<string> { "System.FreeSpace" };

            var storageIdProperties = await allProperties.RetrievePropertiesAsync(propertiesToRetrieve);

            var freeSpaceSize = storageIdProperties["System.FreeSpace"].ToString();
Michael Xu
  • 4,382
  • 1
  • 8
  • 16
  • Thanks. Is there any method to convert the bytes to GB? – mylim Oct 11 '17 at 04:09
  • You need to create a function for that.Please reference the rule of converting Byte to Gigabyte: https://www.unitconverters.net/data-storage/gigabyte-to-byte.htm – Michael Xu Oct 11 '17 at 05:23