VB怎么扫描指定磁盘下的指定格式文件是否存在 固定的一些字符比如扫描 整个C盘下的所有TXT文件把 内容包含 “我爱你” 的所有绝对路径写入list

解决方案 »

  1.   

    '引用 : Microsoft Scripting RuntimePrivate Sub Command1_Click()
    folder_file "E:\temp"
    End Sub
    Public Sub folder_file(strPath As String)
                Dim objFolder As Scripting.Folder '文件夹对象
                Dim objFile As Scripting.File '文件对象
                Dim objSubdirs As Scripting.Folders '文件夹集合对象
                Dim objLoopFolder As Scripting.Folder '文件夹对象
                
                Set m_FSO = New Scripting.FileSystemObject
                            
                Set objFolder = m_FSO.GetFolder(strPath)
                
                For Each objFile In objFolder.Files
                
                rig_path = LCase$(Right$(objFile.ShortPath, 4))
                    If rig_path = ".txt" And InStr(objFile.Name, "我爱你") Then '如果只对文件名:InStr(objFile.Name, "我爱你"),如果是文件路径:InStr(objFile.ShortPath, "我爱你")
                        List1.AddItem Left(objFile.ShortPath, InStrRev(objFile.ShortPath, "\")) & objFile.Name
                    End If
                Next objFile
                
                Set objSubdirs = objFolder.SubFolders
                For Each objLoopFolder In objSubdirs
                    folder_file objLoopFolder.Path
                Next objLoopFolder
                Set objSubdirs = Nothing
                Set objFolder = Nothing
    End Sub
      

  2.   

    现在这个是搜索文件名 如果内容那 除了OPEN 还能怎么样 最重要的是提高速度