[英]Get total size of LocalFolder Windows Phone 8.1
In my app i am using LocalStorage. 在我的应用程序中,我正在使用LocalStorage。 I have saved photos to localfolder.
我已将照片保存到localfolder。 I want total used memory size of localfolder.
我想要localfolder的总已用内存大小。
BasicProperties BP = await ApplicationData.Current.LocalFolder.GetBasicPropertiesAsync();
var size = BP.Size;
Debug.WriteLine("size = {0}", size);
I am using this code but every time I am getting 我正在使用此代码,但每次获得
size = 0
大小= 0
I have looked at this Answer but i don't think its proper way to get total total size of localfolder i don't want to use for loop because there will be hundreds of file in my localfolder. 我已经看过这个答案,但是我不认为它是获取本地文件夹总大小的正确方法,我不想用于循环,因为我的本地文件夹中将有数百个文件。
You have to walk through folders to calculate the size of files inside 您必须浏览文件夹以计算其中的文件大小
public async System.Threading.Tasks.Task<long> GetFolderSize(Windows.Storage.StorageFolder folder)
{
long size = 0;
// For files
foreach (Windows.Storage.StorageFile thisFile in await folder.GetFilesAsync())
{
Windows.Storage.FileProperties.BasicProperties props = await thisFile.GetBasicPropertiesAsync();
size += props.Size;
}
// For folders
foreach (Windows.Storage.StorageFolder thisFolder in await folder.GetFoldersAsync())
{
size += await GetFolderSize(thisFolder);
}
return size;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.