// Copyright (c) Arlo Godfrey. All Rights Reserved. // Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms. // See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information. using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using OwlCore.AbstractStorage; namespace StrixMusic.Sdk.Extensions { /// /// extension methods. /// public static class AbstractStorage { /// /// Searches all files in a folder and including sub folders if any. /// /// A representing the asynchronous operation. Value is the folders in this directory. public static async Task> RecursiveDepthFileSearchAsync(this IFolderData folder) { // Move out of an extension method var files = await folder.GetFilesAsync(); return await RecursiveDepthFileSearchAsync(folder, files.ToList()); } private static async Task> RecursiveDepthFileSearchAsync(IFolderData folderData, IList fileDatas) { var folders = await folderData.GetFoldersAsync(); foreach (var folder in folders) { var files = await folder.GetFilesAsync(); foreach (var file in files) { fileDatas.Add(file); } await RecursiveDepthFileSearchAsync(folder, fileDatas); } return fileDatas; } } }