如何递归搜索c#中的文件夹并报告扫描进度? [英] How to recursively search folders in c# and to report scan progress?

查看:239
本文介绍了如何递归搜索c#中的文件夹并报告扫描进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#创建一个Windows应用程序表单,它应该显示一个特定类型的文件(例如* .tmp)。当我点击表格中的按钮时;搜索应该开始搜索所有* .tmp文件。 LabelBox应显示正在扫描的文件的路径以及每当找到* .tmp文件时;另一个labelbox cound应该增加。



我尝试使用EnumerateFiles但是我收到一条错误消息System.IO.Directory不包含EnumerateFiles。

我尝试过GeFiles,但有了这个,我认为我可以在LabelBox中显示扫描的进度。



可以帮助我如何显示扫描的每个文件或路径表格的标签框和每个成功搜索* .tmp的另一个标签盒都应该增加。用户界面应该是这样的;实际用户应该看到正在扫描哪个文件或路径,他们应该看到labelBox2的cound增加。



谢谢。

I'm creating a windows application form in C# which should display a particular type of file ( say *.tmp for example ) recursilvely. When I click on a Button in the form; the search should begin to search all *.tmp files. The LabelBox should display the path of a file being scanned and whenever a *.tmp file is found; the other labelbox cound should increase.

I tried using EnumerateFiles but I go an error message System.IO.Directory does not contain EnumerateFiles.
I tried GeFiles but with this we can display the progress of scan in LabelBox I think.

Can any help me how to show each file or path being scanned in the labelbox of a form and for each successfull search of *.tmp the other labelbox cound should increase. The UI should like that; the actual users should see which file or path is being scanned and they should see te increase in cound of the labelBox2.

Thank you.

推荐答案

使用 Directory.GetFiles [ ^ ]创建目录中的文件列表。然后,您可以将它们添加到ListBox并按您选择的任何顺序处理它们。
Use Directory.GetFiles[^] to create a list of files in a directory. You can then add them to a ListBox and process them in any order you choose.


使用下面的api,您可以直接获得搜索结果。



来模拟此操作并向用户显示一些进度,您可以使用belwo API收集所有文件,然后通过显示文件的当前文件夹路径和索引器进度来迭代它。



https://msdn.microsoft.com/ en-us / library / ms733069(v = vs.110).aspx [ ^ ]
using below api you can directly get the search result.

to simulate this operation and to show user some progress you can collect all the files using belwo API and then iterate through it by showing current folder path of file and the indexer progress.

https://msdn.microsoft.com/en-us/library/ms733069(v=vs.110).aspx[^]


这篇关于如何递归搜索c#中的文件夹并报告扫描进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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