' Search for files in Folder and Subfolders

folder="c:\temp"
extensions=Array("txt","csv")
nameContains="test"

searchContents=True
contains="test"

useModifiedDate=True
modifiedDateStart=Now-1000
modifiedDateEnd=Now

Set fso = CreateObject("Scripting.Filesystemobject")

Search fso.GetFolder(folder)

Sub Search(myfolder)

  For Each file In myfolder.Files
  
    match=False
    
    If useModifiedDate=False Or _
     (useModifiedDate And file.DateLastModified>=modifiedDateStart _
     And file.DateLastModified<=modifiedDateEnd) Then
    
      ext=LCase(Mid(file.Name,InStrRev(file.Name,".")+1))
      For Each extension In extensions 
        If StrComp(extension,ext,vbTextCompare)=0 Then
      
          If InStr(1,file.Name,nameContains,vbTextCompare)>0 Then
          
            If searchContents Then
              Set f=fso.OpenTextFile(file.Path,1)
              contents=f.ReadAll
              f.Close
              If InStr(1,contents,contains,vbTextCompare)>0 Then
                match=True
              End If
            Else
              match=True
            End If
          End If  
        
          If match Then
            WScript.Echo file.path
          End If  
          
          Exit For
        End If
      Next
      
    End If
  Next

  For Each subfolder In myfolder.SubFolders
    Search subfolder
  Next
  
End Sub

search for scripts

VbsEdit contains all these sample scripts!


Download Now!



Download   Home   Scripts

Copyright © 2001-2026 adersοft