/// <summary> /// Recurively collects information about this directory and each subdirectory. The optional 'level' is the max amount of sub folders to collect information on. /// </summary> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="InvalidFileSearchException"></exception> /// <exception cref="NotDirectoryException"></exception> DirectoryDataSnapshot GetDirectoryDataDeep(string path, int level = -1) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var fsd = GetFileSystemData(path); if (!fsd.IsDirectory) { throw new NotDirectoryException(path); } // Get the DirectoryData from the system, then convert it so it can accept more information about files and directories var dir = new DirectoryDataSnapshot((DirectoryData)fsd); foreach (var item in EnumerateDirectoryContents(path)) { var itemPath = _pathUtility.Combine(path, item.Name); if (item.IsDirectory) { // allows -1 to do complete search. if (level != 0) { dir.Add(GetDirectoryDataDeep(itemPath, level - 1)); } } else { dir.Add((FileData)item); } } return(dir); }
public void Add(DirectoryDataSnapshot dir) => _directories.Add(dir);
/// <summary> /// Recurively collects information about this directory and each subdirectory. The optional 'level' is the max amount of sub folders to collect information on. /// </summary> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="InvalidFileSearchException"></exception> /// <exception cref="NotDirectoryException"></exception> DirectoryDataSnapshot GetDirectoryDataDeep(string path, int level = -1) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var fsd = GetFileSystemData(path); if (!fsd.IsDirectory) { throw new NotDirectoryException(path); } // Get the DirectoryData from the system, then convert it so it can accept more information about files and directories var dir = new DirectoryDataSnapshot((DirectoryData)fsd); foreach (var item in EnumerateDirectoryContents(path)) { var itemPath = _pathUtility.Combine(path, item.Name); if (item.IsDirectory) { // allows -1 to do complete search. if (level != 0) { dir.Add(GetDirectoryDataDeep(itemPath, level - 1)); } } else { dir.Add((FileData)item); } } return dir; }