golldy
golldy

Reputation: 1299

Recursively find the sub folders file count in window phone 8.1

I am trying to get the number of files that is contained in the KnownFolder.MusicLibrary or any of the media classes. I am unable to get the count for the sub folders in an artist folder. Would i be able to do this ?

Upvotes: 0

Views: 315

Answers (1)

Sajeev C
Sajeev C

Reputation: 1538

Try this code. But this question is already 3 months old. So, I hope you already found out a way to do this. If yes, post your answer. It may come handy for someone else.

Visit this link. It has a very nice documentation. After I access Folders from Video library using GetFoldersAsync(), I pass it a function. And the function iterates through each Video Library Item & checks whether it is a folder or a file. If it is a folder, contents residing inside the function are found out using GetItemsAsync() & it's count is determined & returned. If it's already a file, it's count is returned.

hope this helps. And mark it as answer if it was helpful.

    IReadOnlyList<IStorageItem> VideoLibrary = await KnownFolders.VideosLibrary.GetFoldersAsync();
    int count= GetCount(VideoLibrary);
    private async Task<string> GetCount(IReadOnlyList<IStorageItem> VideoLibraryItems)
    {
            foreach (IStorageItem vItem in VideoLibraryItems)
            {
                IStorageItem item = vItem;
                if (item.IsOfType(Windows.Storage.StorageItemTypes.Folder))
                {
                    StorageFolder sfolder = (StorageFolder)item;
                    IReadOnlyList<IStorageItem> fileList = await sfolder.GetItemsAsync();
                    return fileList.Count
        }
                else if(item.IsOfType(Windows.Storage.StorageItemTypes.File))
        {
                    StorageFile sf = (StorageFile)item;
        return sf.Count;
                }
            }
    }

Upvotes: 1

Related Questions