I have an Windows 8.1 Store App. I am trying to find the Local Folder Size.?(e.g. 210 MB)
I have an application which would download some of content into my local folder. I want to check the size of my local folder (such as how many MB are currently there).
I have tried looking through MSDN and Google but haven't been able to find anything on it.
Note : I have a folder and subfolder so not only files which is in local folder..
You are able to access the
LocalFolder
via theApplicationData.LocalFolder
property.This
LocalFolder
is aStorageFolder
object.StorageFolder
has a method calledGetBasicPropertiesAsync
.GetBasicPropertiesAsync
returns aBasicProperties
object. ThisBasicProperties
object has aSize
property which tells you the size of the item in question (folder or file). I believe thatSize
is in bytes (aulong
).The complete command can be done in a single line in an
async
method like this:(await ApplicationData.LocalFolder.GetBasicPropertiesAsync()).Size;
You can also split up each step if you need any other information.
Edit: Apparently this does not work as well as hoped. The solution is to create a query and sum up all of the files. You can do this using Linq.
The C# solution is fine for small-medium size folders but if your app (for whatever reason) has large amount of files this method will take a lot of time and you may even run out of memory. I ran into this situation and opted to write a c++ winrt component that gets the size of a folder and I can attest that it runs much faster and with less memory. The code for the function is below, in the c# code you can call GetAppUsedSpace using the LocalState folder's Path property.