VB全扫描 [英] VB Full scan
问题描述
好了,我想让用户从组合框中选择一个根目录(例如,"C:\").一旦发生这种情况,将启用开始"按钮,并在文本框中显示带有我已加载文件名的文本文件.用户单击开始以扫描C驱动器,并且标签显示计算机正在寻找的文本文件中的目录和文件名.........
我对递归并不满意,并且已经尝试了好几天了.我有了递归的想法,并且知道这可能是扫描计算机文件夹和子文件夹的最有效方法,但是我真正需要的是一个完整的示例单词,而哪个对象控制着哪一行代码……请我非常想了解递归,并且需要帮助使我的扫描仪搜索整个目录而不仅仅是一个级别.
Ok to start I would like to have the user select a root directory from a combobox (Example, "C:\"). Once that happens the start button is enabled and the text file with my loaded file names is displayed in a textbox. The user clicks start to scan the C drive and the label shows the directory and file name from the text file that the computer is looking for.........
I am no good with recursion and have been trying to learn it for days. I get the idea of recursion and know it may be the most efficient way to scan a computers folders and sub folders but what I truly need is a full example word for word and what object controls what line of code...... Please I am desperate to understand recursion and need help to make my scanner search the entire directory and not just one level.
推荐答案
虽然我建议您尝试学习递归,实际上,这里不需要. IO名称空间中的GetFiles方法将使您可以找到给定目录及其子目录中的所有文件.
像这样的东西:
While I recommend that you try to learn recursion, actually it''s not needed here. The GetFiles method in the IO namespace will let you find all files in a given directory AND it''s subdirectories.
Something like this:
Imports System.IO
Dim dir As New DirectoryInfo("C:\")
For Each foundFile As FileInfo In dir.GetFiles("*.*", SearchOption.AllDirectories)
'Do Magic here
Next foundFile
在这种情况下,AllDirectories标志指定它应递归遍历所有子目录...
In this case, the AllDirectories flag specifies that it should loop through all subdirectories recursively...
一个示例(只为您编写!): [
An example (written just for you!): "Directory.GetFiles Method (String)"[^] atMSDN
.
:-)
这篇关于VB全扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!