kinda working

This commit is contained in:
Matt Parker [SSW]
2025-01-10 19:56:26 +10:00
parent 614893bf1a
commit e53bde1776
3 changed files with 77 additions and 9 deletions

View File

@@ -3,8 +3,9 @@
public class Folder
{
public required string Name { get; set; }
public List<Folder> Folders { get; set; } = [];
public List<MyFile> Files { get; set; } = [];
public required string FullName { get; set; }
public required Folder? ParentFolder { get; set; }
public required List<MyFile> Files { get; set; } = [];
}
public class MyFile

View File

@@ -37,4 +37,61 @@ public static class GetNodesInSolution
.ToList();
return files;
}
public static List<Folder> GetFoldersInProject(string projectPath)
{
var files = GetFilesInProject(projectPath);
var rootDirectoryOfProject = new DirectoryInfo(Path.GetDirectoryName(projectPath)!);
var grouped = files.GroupBy(s => s.Directory!.FullName);
var folders = grouped.Select(s => new Folder
{
Name = Path.GetFileName(s.Key),
FullName = s.Key,
ParentFolder = null,
Files = s.Select(f => new MyFile
{
Name = f.Name
}).ToList()
}).ToList();
foreach (var folder in folders)
{
var directoryInfo = new DirectoryInfo(folder.FullName);
if (directoryInfo.FullName == rootDirectoryOfProject.FullName) continue;
var parent = directoryInfo.Parent;
try
{
var parentFolder = folders.SingleOrDefault(f => f.FullName == parent!.FullName);
folder.ParentFolder = parentFolder;
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return folders;
}
}