目录文件列表实用程序,包括子目录 [英] Directory file listing utility, including sub directories

查看:294
本文介绍了目录文件列表实用程序,包括子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

现在,我正在创建vb.net 2010项目,并且在创建子功能时会遇到一些问题,该子功能将列出所有文件,包括子目录中的文件.

创建一个脚本将列出一个目录中的所有文件,而不列出所有子目录是非常容易的.
有人可以告诉我此文件列表功能所需的代码吗?

我知道对于C ++,有一个使用C ++的项目.
我正在寻找与VB.net相同类型的脚本.

http://www.codeproject.com/KB/files/GetFileList.aspx

谢谢:)

Hello,

Right now I am creating a vb.net 2010 project and I am having some issues with creating a sub function that will list all files including files in sub directories.

It is very easy to create a script that will list all files in a directory but not all sub directories.
Could someone please tell me the code that I need for this file listing function?

I know for C++ there is a project for this using C++.
I am looking for the same type of script but for VB.net.

http://www.codeproject.com/KB/files/GetFileList.aspx

Thank you :)

推荐答案

类似的事情可能为您解决:

Something like this might solve it for you:

Imports System.IO

Module Module1

    Sub Recurse(ByVal directory As DirectoryInfo, ByVal resultList As List(Of FileInfo))
        resultList.AddRange(directory.GetFiles())

        For Each subDirectory As DirectoryInfo In directory.GetDirectories()
            Recurse(subDirectory, resultList)
        Next
    End Sub


    Sub Main()
        Dim flatList As List(Of FileInfo)

        flatList = New List(Of FileInfo)
        Recurse(New DirectoryInfo("C:\Projects"), flatList)

        For Each f As FileInfo In flatList
            System.Console.WriteLine(f.FullName)
        Next


    End Sub

End Module



希望这会有所帮助,
弗雷德里克(Fredrik)



Hope this helps,
Fredrik


这篇关于目录文件列表实用程序,包括子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆