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

Vignesh Govindhan 26 Reputation points
2020-06-11T02:01:15.727+00:00

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();
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,191 Reputation points
    2020-06-11T05:26:08.69+00:00

    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);
    
    0 comments No comments

0 additional answers

Sort by: Most helpful