文件搜索子目录 [英] File search subdirectories

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

问题描述

不要登上所有人,但我会从头开始解决问题.
我正在尝试使用get file语句搜索子目录.我希望用户首先使用组合框选择基本文件夹C:\.然后,单击事件将扫描基本文件夹C:\中的所有文件夹和子文件夹.我现在已经待了好几天了,感到非常疲惫和沮丧.我目前的代码需要容纳至少4个项目.....

1)组合框-用于基本文件夹\根目录C:或D:或E:
2)开始扫描按钮,单击事件
3)停止扫描按钮单击事件
4)删除按钮单击事件

有人可以给我一个可行的例子,让我今晚睡觉吗?.....这确实使我分崩离析以解决这个问题,我觉得我已经非常接近找到答案了.这是我在开始按钮单击事件中正在使用的代码....

Not to board everyone but I will take my problem from the top..
I am trying to search subdirectories with the get file statement. I would like the user to first choose the base folder C:\ with a combobox. The click event will then scan all folders and subfolders in the basefolder C:\. I have been at this now for days and am very exhausted and frustrated. My code as it stands needs to accommodate atleast 4 items.....

1) Combobox - for base folder\ root directory C: or D: or E:
2) Start Scan Button Click Event
3) Stop Scan Button click event
4) Delete button click event

Can someone please Give me a working example of this so I can sleep tonight?....... it is literally chewing me apart to figure this out and I feel as thoe I am so close to finding the answer. Here is the code I am working for in my start button click event....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim searchForTheseFiles() As String = TextBox1.Text.ToUpper.Split(Environment.NewLine)
        Dim fileList As New List(Of String)(searchForTheseFiles)
        Dim myDir As New DirectoryInfo(CheckedComboBoxEdit1.Text)
        Try
            Dim searchForTheseFiles() As String = TextBox1.Text.ToUpper.Split(Environment.NewLine)
        Dim fileList As New List(Of String)(searchForTheseFiles)
        Dim myDir As New DirectoryInfo(CheckedComboBoxEdit1.Text)
        Try
            Dim files() As FileInfo = myDir.GetFiles("*.*", SearchOption.AllDirectories)
            For Each foundFile As FileInfo In files
                If fileList.Contains(foundFile.Name.ToUpper) Then
                    ListBox3.Text &= Environment.NewLine & foundFile.FullName
                    My.Computer.Audio.Play(My.Resources.fat_n_soft_button_4, AudioPlayMode.Background)
                End If
            Next
        Catch ex As UnauthorizedAccessException
            Debug.WriteLine(String.FormatCould not access directory '{0}'." myDir.FullName))
        End Try
End Sub



这段代码有什么问题吗?谁能解释为什么当用户在组合框中选择一个子目录时却不搜索子目录?

这是我的comboboxedit1获取逻辑目录



Is there anything wrong with this code? can anyone explain why it is not searching the subdirectory when the user chooses one in the combobox?

here is my comboboxedit1 get logical directory

comboboxedit1.properties.items.addrange(system.io.directory.getlogicaldrives)



为了上帝的爱!!!!



FOR THE LOVE OF GOD PLEASE!!!!

推荐答案

在这里看看:
http://www.codeguru.com/forum/showthread.php?t=344379 [ ^ ]

然后在这里:
http://msdn.microsoft.com/zh-cn/library/system.security.permissions.fileiopermission%28v = VS.71%29.aspx [
Have a look here:
http://www.codeguru.com/forum/showthread.php?t=344379[^]

And here:
http://msdn.microsoft.com/en-us/library/system.security.permissions.fileiopermission%28v=VS.71%29.aspx[^]

Good luck!


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

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