Jump to content

Search Engine


Recommended Posts

Hello,

As I was fed up of the search engine of windows, I decided to create my own...

Can search word inside txt, ini, au3,...

Much faster than Windows...

If you leave blank the 'word inside file' then it search for files only!

Filters like: *.* or *.jpg,...

enjoy

#include <File.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $sRet
Local $j , $aArayFound[1] , $a=0 , $b=0

#Region ### START Koda GUI section ### Form=
$Gui = GUICreate("Search Engine", 553, 535, -1, -1)
$iFolder = GUICtrlCreateInput("Folder to look in", 160, 10, 121, 21, $ES_READONLY)
$bChoose = GUICtrlCreateButton("Choose Folder", 290, 10, 91, 21)
$iFilter = GUICtrlCreateInput("Filter: *.*", 160, 50, 121, 21)
$iWord = GUICtrlCreateInput("word inside file", 160, 90, 121, 21)
$eEdit = GUICtrlCreateEdit("", 0, 120, 551, 411)
$bSearch = GUICtrlCreateButton("Search", 290, 50, 91, 61,$BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;http://www.autoitscript.com/forum/topic/126552-solved-guictrlcreateinput-question/
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bChoose
            $sPath=FileSelectFolder ( "Choose Folder", "" , 0 , "" , GUICreate("") )
            GUICtrlSetData( $iFolder, $sPath)
        Case $GUI_EVENT_PRIMARYDOWN
            $aCInfo = GUIGetCursorInfo($Gui)
            If $aCInfo[4] = $iFilter And $a = 0 Then
                GUICtrlSetData($iFilter, "")
                $a = 1
            EndIf
            If $aCInfo[4] = $iWord And $b = 0 Then
                GUICtrlSetData($iWord, "")
                $b = 1
            EndIf
        Case $bSearch
            If Not (StringInStr(GUICtrlRead($iFolder), ":\")) Then
                $MsgBox=MsgBox(5 + 16 , "Error", "The input folder is not correct:"&@CRLF&"Retry = Choose an another"&@CRLF&"Cancel = Exit")
                If $MsgBox <> 4 Then
                    Exit
                EndIf
            EndIf
            If StringInStr(GUICtrlRead($iFilter), "Filter") Then
                $MsgBox=MsgBox(5 + 16 , "Error", "The input filter is not correct:"&@CRLF&"Retry = Choose an another"&@CRLF&"Cancel = Exit")
                If $MsgBox <> 4 Then
                    Exit
                EndIf
            EndIf
            If StringInStr(GUICtrlRead($iWord), "word inside file") Then
                GUICtrlSetData( $iWord, "")
            EndIf
            GUICtrlSetData($eEdit, "Please Wait...")
            _Search(GUICtrlRead($iWord), GUICtrlRead($iFilter), GUICtrlRead($iFolder))
    EndSwitch
WEnd





Func _Search($sSearchString, $sFindFile , $sPath)
    $aRetArray =  _FindPathName($sPath, $sFindFile)
    If $sSearchString <> "" Then
        For $i = 1 To $aRetArray[0]-1
            $file = FileOpen($aRetArray[$i], 0)
            If $file = -1 Then
            Else
                $text = FileRead($file)
                If StringInStr( $text , $sSearchString, 1)>0 Then
                    $j += 1
                    ReDim $aArayFound[$j+1]
                    $aArayFound[$j]=$aRetArray[$i]
                EndIf
            EndIf
            FileClose($file)
        Next
    ;~      _ArrayDisplay($aArayFound, "List of file with the String: "&$sSearchString&" found")
        $sEdit = ""
        For $i = 1 To UBound($aArayFound)-1
            $sEdit &= $aArayFound[$i] & @CRLF
        Next
            GUICtrlSetData($eEdit, $sEdit)
    Else
    ;~      _ArrayDisplay($aRetArray,"List of folders found")
        $sEdit = ""
        For $i = 1 To UBound($aRetArray)-1
            $sEdit &= $aRetArray[$i] & @CRLF
        Next
            GUICtrlSetData($eEdit, $sEdit)
    EndIf
EndFunc

;~ http://www.autoitscript.com/forum/topic/95160-file-searcher
; Searches all subfolders of $sPath for $sFindFile (* and ? wildcards accepted)
; Returns an array containing full path and name of all matches.
; Number of matches is in zero index of array
Func _FindPathName($sPath, $sFindFile)
    ;ConsoleWrite($sPath & @CRLF)
    Local $sSubFolderPath, $iIndex, $aFolders
    $search = FileFindFirstFile($sPath & "\" & $sFindFile)
    $aFolders = _FileListToArray($sPath, "*", 2)
    $error=@error
    While 1
        $file = FileFindNextFile($search)
        If @error Then
            ExitLoop
        Else
            $sRet &= $sPath & "\" & $file & "|"
        EndIf
    WEnd
    FileClose($search)
    If $error = 0 Then ; no folder
        For $iIndex = 1 To $aFolders[0]
            $sSubFolderPath = $sPath & "\" & $aFolders[$iIndex]
            $aFoldersSubs = _FileListToArray($sSubFolderPath, "*", 2)
            If IsArray($aFoldersSubs) Then _FindPathName($sSubFolderPath, $sFindFile)
        Next
    EndIf
    Return StringSplit(StringTrimRight($sRet,1), "|")
EndFunc  ;==>_FindPathName

I took some part of 'Malkey' 's script

And an another part of 'Melba23' 's script

Cramaboule

EDIT1: Corrected referance

EDIT2: Changed program

Edited by cramaboule
Link to comment
Share on other sites

And about search inside of files (like .txt, .inf, .log, .ini and etc).

Thanks for sharing...

That't what it does.... Maybe I explain myself wrong ...

It does look inside files even *.au3 !!!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...