question

VigneshGovindhan-1617 avatar image
0 Votes"
VigneshGovindhan-1617 asked ·

BasicProperties.RetrievePropertiesAsync(new List() { "System.Size"}) gives folder size as zero

I am trying to get the size of the folder. I tried the following ways, both of them gives the size as 0 or null

Method 1:


 IDictionary<string,object> property = await storageFolder.Properties.RetrievePropertiesAsync((new List<string>() { "System.Size"}));

Method 2:


 IStorageItem selectedStorageItem = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); 
 BasicProperties properties = await selectedStorageItem.GetBasicPropertiesAsync();
windows-uwp
10 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

Hello,

Welcome to Microsoft Q&A!

The folder itself doesn't seem to have a size, the total size of folder is the sum of the sizes of the files inside the folder. So if you want to get the size of folder, it's better to calculate it by iterating on all files in the folder. For example:

 var folders = folder.CreateFileQuery(CommonFileQuery.OrderByName);
 var fileSizeTasks = (await folders.GetFilesAsync()).Select(async file => (await file.GetBasicPropertiesAsync()).Size);
 var sizes = await Task.WhenAll(fileSizeTasks);
 var folderSize = sizes.Sum(singleSize => (long)singleSize);
10 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.