将Visual Studio文件夹结构导出到Excel

时间:2018-10-05 08:44:30

标签: c# .net excel visual-studio solution

是否可以将Visual Studio“解决方案资源管理器”结构导出到excel中?

我尝试了“ tree”命令,并通过Windows命令提示符将其裁剪为:Like this

但是很难拆分到每个Excel出售的产品。 我期望这样的结果:

enter image description here

那么有什么好主意吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

这里您有解决方案。简单简单的递归解决方案,以所需格式列出文件

public class GetFilesTreeList
{
    private static List<Files> files = new List<Files>();

    public static void Main(string[] args)
    {
        var path = @"C:\Users\Lukasz\Desktop";

        files.Add(new Files(Path.GetFileName(path), 0));
        WriteFilesRec(path, 1);

        foreach (var filese in files)
        {
            Console.WriteLine(filese);
        }

    }

    public class Files {
        public int column;
        public string name;

        public Files(string name, int column)
        {
            this.column = column;
            this.name = name;
        }

        public override string ToString()
        {
            return new String('+', column) + name; 
        }
    }

    public static void WriteFilesRec(string path, int i) {
        DirectoryInfo directory = new DirectoryInfo(path);
        foreach(var d in directory.GetDirectories()) {
            files.Add(new Files(d.Name, i));
            WriteFilesRec(Path.Combine(path, d.Name), i+1);
        }
        foreach(var f in directory.GetFiles()) {
            files.Add(new Files(f.Name, i));
        }
    }
}