' 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)

  ForEach fileIn myfolder.Files
  
    match=False
    
    If useModifiedDate=FalseOr _
     (useModifiedDateAnd file.DateLastModified>=modifiedDateStart _
     And file.DateLastModified<=modifiedDateEnd) Then
    
      ext=LCase(Mid(file.Name,InStrRev(file.Name,".")+1))
      ForEach extensionIn extensions
        If StrComp(extension,ext,vbTextCompare)=0Then
      
          If InStr(1,file.Name,nameContains,vbTextCompare)>0Then
          
            If searchContentsThen
              Set f=fso.OpenTextFile(file.Path,1)
              contents=f.ReadAll
              f.Close
              If InStr(1,contents,contains,vbTextCompare)>0Then
                match=True
              EndIf
            Else
              match=True
            EndIf
          EndIf  
        
          If matchThen
            WScript.Echo file.path
          EndIf  
          
          ExitFor
        EndIf
      Next
      
    EndIf
  Next

  ForEach subfolderIn myfolder.SubFolders
    Search subfolder
  Next
  
EndSub

search for scripts

VbsEdit contains all these sample scripts!


Download Now!



Download   Home   Scripts

Copyright © 2001-2024 adersοft