mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 12:14:44 -04:00
Enhanced DirectoryService to exclude System and Hidden folders.
This commit is contained in:
parent
fbe2daac6a
commit
b899157015
@ -53,7 +53,7 @@ namespace API.Controllers
|
|||||||
return Ok(Directory.GetLogicalDrives());
|
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));
|
return Ok(_directoryService.ListDirectory(path));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using API.Interfaces;
|
using API.Interfaces;
|
||||||
|
|
||||||
@ -7,15 +10,22 @@ namespace API.Services
|
|||||||
{
|
{
|
||||||
public class DirectoryService : IDirectoryService
|
public class DirectoryService : IDirectoryService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Lists out top-level folders for a given directory. Filters out System and Hidden folders.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rootPath">Absolute path </param>
|
||||||
|
/// <returns>List of folder names</returns>
|
||||||
public IEnumerable<string> ListDirectory(string rootPath)
|
public IEnumerable<string> ListDirectory(string rootPath)
|
||||||
{
|
{
|
||||||
// TODO: Filter out Hidden and System folders
|
// TODO: Put some checks in here along with API to ensure that we aren't passed a file, folder exists, etc.
|
||||||
// DirectoryInfo di = new DirectoryInfo(@path);
|
|
||||||
// var dirs = di.GetDirectories()
|
|
||||||
// .Where(dir => (dir.Attributes & FileAttributes.Hidden & FileAttributes.System) == 0).ToImmutableList();
|
|
||||||
//
|
|
||||||
|
|
||||||
return Directory.GetDirectories(@rootPath);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user