Search code examples
c#storageraspberry-pi3usb-drivewindows-iot-core-10

Windows IoT Raspberry Pi 3 C# GetDiskFreeSpace


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..


Solution

  • 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();