【问题标题】:populating datagridview with files in multiple subfolderse使用多个子文件夹中的文件填充 datagridview
【发布时间】:2012-04-17 02:05:48
【问题描述】:

我在尝试使用简单文件填充我的datagridview 时遇到了设计问题。

我在Settings 文件中声明了一个主目录。我需要我的datagridview 在 7 个子文件夹中搜索这个父目录。每个子文件夹都有一堆子文件夹(我正在管理的机器的名称)。其中每一个都包含我需要添加到网格中的文件。

例子:

C:\Users\me\Documents\MASTERDIRECTORY\Folder7\Machine Name1\file.txt

C:\Users\me\Documents\MASTERDIRECTORY\Folder7\Machine Name2\file.txt

显然需要某种递归代码来执行搜索,但我应该如何开始?性能方面,我应该将这些文件路径添加到数组列表中,然后将其转换为我的网格吗?

【问题讨论】:

    标签: c# recursion datagridview filesystems


    【解决方案1】:

    这样的事情可能会有所帮助:-

    string filePath = @"C:\Users\me\Documents\MASTERDIRECTORY\Folder7"
    
                    foreach (string Folder in Directory.GetDirectories(filePath))
                    {
    
                      foreach (string file in Directory.GetFiles(Folder))
                         {
                           // here you can grab the log file path and add it to you Gridview
                         }
    
                    }
    

    【讨论】:

    • 或者您可以构建一个数组/列表,然后将其添加为您的 Gridview 的数据源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多