首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >文件搜索花费的时间太长

文件搜索花费的时间太长
EN

Stack Overflow用户
提问于 2015-05-21 03:16:28
回答 1查看 176关注 0票数 0

我们需要在一个网络硬盘上释放一些空间。有问题的目录有526 in的数据,180914个文件在13555个目录中。

因此,我编写了查找文件副本的代码。用户指定要查找的文件,应用程序将查找该文件的所有实例。它工作得很好,只是需要几分钟。我对此并不感到惊讶,但在windows explorer中同样的搜索速度更快。

我认为这是因为我运行我的应用程序,然后在Windows资源管理器中执行相同的搜索,在相同的文件夹中搜索相同的文件。

有一个区别,我只是不知道它有多重要……

因为一些搜索到的文件具有相同的名称(比如操作MANUAL.PDF),但是它们是不同的,所以我会在找到匹配的文件时比较大小。所以搜索找到一个文件,我检查文件大小,只返回具有相同名称和文件大小的文件。

我在一个特定的搜索中得到了5,explorer返回了74。

我的应用需要2分钟,浏览器需要1分钟。

我能做些什么来提高效率吗?我希望我能够大致了解explorer的性能。

这是代码。

代码语言:javascript
运行
复制
'find all instances of the file
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'first clear the listbox
        LB_Files.Items.Clear()


        'set the lbel text for the list box
        Label1.Text = "Finding all instances of:  " & TB_File.Text & " in directory:  " & TB_Drive.Text & " and all sub-driectories... PLEASE STAND BY"
        'make sure the label updates
        Me.Refresh()

        'run through and find each file and add it to the listbox
        For Each foundFile As String In My.Computer.FileSystem.GetFiles(TB_Drive.Text, Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, TB_File.Text)

            'check if the file is a shortcut and if it is do nothing
            If foundFile.Contains(".lnk") Then

            Else

                Dim infoReader As System.IO.FileInfo
                infoReader = My.Computer.FileSystem.GetFileInfo(foundFile)
                newfilesize = infoReader.Length
                'MsgBox("The old file size is: " & oldfilesize & ",  and the new file size is:  " & newfilesize)
                'for each file that is not a shortcut, add it to the list box

                'check if the file sizes match, don't want to add a file if it is not the same file
                If newfilesize = oldfilesize Then

                    LB_Files.Items.Add(foundFile)
                    'update the file count
                    count = count + 1
                    newfilesize = 0

                End If
                'reset the newfilesize
                newfilesize = 0
            End If


        Next
        'once we find all the files, change the lable to say how many we have.
        Label1.Text = "Found " & count.ToString & " instances of " & TB_File.Text & "."

    End Sub
EN

Stack Overflow用户

发布于 2015-05-21 05:56:11

它是一台windows服务器吗?

如果是这样,那么我就不会费心进行迭代搜索,而是学习更多关于文件系统的知识。通过搜索索引,您可以更快地找到文件。

看一看Fast Search On FAT32/NTFS File System

从被接受的答案中,你会找到一个sourceforge项目,它索引驱动器-将这个部分转换为vb,并快速搜索文件。或者,您可以使用众多免费工具中的一个来实现此目的。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30358524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档