VB.NET中的文件夹搜索器 [英] Folder Searcher in VB.NET

查看:121
本文介绍了VB.NET中的文件夹搜索器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们请给我一些示例代码,说明如何在驱动器中搜索特定文件夹,并在listview中列出具有相同名称的所有文件夹。

解决方案

< blockquote>您需要在每个驱动器的顶层开始搜索,并使用Directory.GetDirectories方法检索要比较的目录列表。您将使用这些目录中的每一个来继续搜索匹配的目录。在伪代码中,您的算法将如下所示:

函数MatchDirectory  - 传递路径到文件夹(例如C:\)
使用<获取此文件夹下的目录数组;代码> Directory.GetDirectories< /代码>使用你传入的文件夹路径。
如果没有目录,则返回此函数
对于目录数组中的每个条目
获取目录名称(从末尾开始的简单搜索)前一个\的字符串将执行此操作)。
如果目录名与您要搜索的目录名匹配,请将全名添加到ListView。
调用MatchDirectory,传入当前目录条目
结束
结束


Friends please give me some sample code that shows how to search a drive for a specific folder and list all the folder with same name in a listview with path.

解决方案

You need to start searching at the top level of each drive and use the Directory.GetDirectories method to retrieve a list of directories that you want to compare. You will use each of these directories to keep searching for the matching directories. In pseudo-code, your algorithm will look something like this:

Function MatchDirectory - pass in a path to a folder (e.g. C:\)
  Get the array of directories under this folder using <code>Directory.GetDirectories</code> using the folder path you passed in.
  If there are no directories, return out of this function
  For each entry in the directory array
    Get the directory name (a simple search from the end of the string to the previous \ will do it).
    If the directory name matches the one you're searching for, add the full name to your ListView.
    Call MatchDirectory, passing in the current directory entry
  End 
End


这篇关于VB.NET中的文件夹搜索器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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