diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs index 0c6e45d99..4800a8cbb 100644 --- a/API/Controllers/LibraryController.cs +++ b/API/Controllers/LibraryController.cs @@ -53,7 +53,7 @@ namespace API.Controllers return Ok(Directory.GetLogicalDrives()); } - if (!Directory.Exists(@path)) return BadRequest("This is not a valid path"); + if (!Directory.Exists(path)) return BadRequest("This is not a valid path"); return Ok(_directoryService.ListDirectory(path)); } diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.cs index 1b333b74c..49de3db48 100644 --- a/API/Services/DirectoryService.cs +++ b/API/Services/DirectoryService.cs @@ -1,5 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; +using System.Linq; using System.Threading.Tasks; using API.Interfaces; @@ -7,15 +10,22 @@ namespace API.Services { public class DirectoryService : IDirectoryService { + /// + /// Lists out top-level folders for a given directory. Filters out System and Hidden folders. + /// + /// Absolute path + /// List of folder names public IEnumerable ListDirectory(string rootPath) { - // TODO: Filter out Hidden and System folders - // DirectoryInfo di = new DirectoryInfo(@path); - // var dirs = di.GetDirectories() - // .Where(dir => (dir.Attributes & FileAttributes.Hidden & FileAttributes.System) == 0).ToImmutableList(); - // - - return Directory.GetDirectories(@rootPath); + // TODO: Put some checks in here along with API to ensure that we aren't passed a file, folder exists, etc. + + var di = new DirectoryInfo(rootPath); + var dirs = di.GetDirectories() + .Where(dir => !(dir.Attributes.HasFlag(FileAttributes.Hidden) || dir.Attributes.HasFlag(FileAttributes.System))) + .Select(d => d.Name).ToImmutableList(); + + + return dirs; } } } \ No newline at end of file