mylim
mylim

Reputation: 313

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

Upvotes: 0

Views: 339

Answers (1)

Michael Xu
Michael Xu

Reputation: 4432

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

Upvotes: 1

Related Questions