mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Interfaces;
|
|
|
|
namespace API.Services
|
|
{
|
|
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)
|
|
{
|
|
// 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;
|
|
}
|
|
}
|
|
} |