Jump to content
Sign in to follow this  
cramaboule

Search and search IN file

Recommended Posts

cramaboule

Here my srcipt for searching files and/or searching inside files.

Made long time ago with the help of this forum.

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

Global $sRet[1] = ["0"], $flag, $percent
Local $j, $aArayFound[1], $a = 0, $b = 0, $sFolder = "", $debug = 0

;~ _ArrayDisplay( $sRet , "$sRet")

#Region ### START Koda GUI section ### Form=
$Gui = GUICreate("Search Engine", 554, 559, -1, -1)
If $debug Then
    $iFolder = GUICtrlCreateInput("C:\Users\Admin\au3", 160, 10, 121, 21, $ES_READONLY)
    $iFilter = GUICtrlCreateInput("*.au3", 160, 40, 121, 21)
    $iWord = GUICtrlCreateInput("gui", 160, 70, 121, 21)
Else
    $iFolder = GUICtrlCreateInput("Folder to search in", 160, 10, 121, 21, $ES_READONLY)
    $iFilter = GUICtrlCreateInput("filter *.*", 160, 40, 121, 21)
    $iWord = GUICtrlCreateInput("word inside file", 160, 70, 121, 21)
EndIf
$bSearch = GUICtrlCreateButton("Search", 290, 40, 91, 50, $BS_DEFPUSHBUTTON)
$bChoose = GUICtrlCreateButton("Choose Folder", 290, 10, 91, 21)
$lLabel = GUICtrlCreateLabel("", 6, 130, 541, 70)
$pProgress = GUICtrlCreateProgress(160, 100, 217, 25)
$eEdit = GUICtrlCreateEdit("", 3, 201, 548, 354)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetLimit($eEdit, 2147000000)

;~ GUICtrlSetData( $iFolder, "C:\")
;~ GUICtrlSetData( $iFilter, "*.aif")
;~ GUICtrlSetData( $iWord, "")


;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(""))
;~             $sPath=FileOpenDialog ( "Choose", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All (*.*)" , 7 , "", 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
            $flag = 0
            $f = 1
            If Not (StringInStr(GUICtrlRead($iFolder), ":\")) Then
                $MsgBox = MsgBox(5 + 16, "Error", "The input folder is not correct:" & @CRLF & "Retry = Choose an another Folder" & @CRLF & "Cancel = Exit")
                If $MsgBox <> 4 Then
                    Exit
                Else
                    $f = 0
                EndIf
            EndIf
            If StringInStr(GUICtrlRead($iFilter), "Filter") And $f = 1 Then
                $MsgBox = MsgBox(5 + 16, "Error", "The input filter is not correct:" & @CRLF & "Retry = Choose an another Filter" & @CRLF & "Cancel = Exit")
                If $MsgBox <> 4 Then
                    Exit
                Else
                    $f = 0
                EndIf
            EndIf
            If StringInStr(GUICtrlRead($iWord), "word inside file") Then
                GUICtrlSetData($iWord, "")
            EndIf
            If StringRight(GUICtrlRead($iFolder), 1) = "\" Then
                $sFolder = StringTrimRight(GUICtrlRead($iFolder), 1)
            Else
                $sFolder = GUICtrlRead($iFolder)
            EndIf
            If $f Then
                GUICtrlSetData($eEdit, "Please wait...")
                _Search(GUICtrlRead($iWord), GUICtrlRead($iFilter), $sFolder)
            EndIf
    EndSwitch
WEnd





Func _Search($sSearchString, $sFindFile, $sPath)
;~     ConsoleWrite($sSearchString&"--"&$sFindFile&"--"&$sPath & @LF)
    Dim $aRetArray[1], $aArayFound[1]
    Global $sRet[1] = ["0"]
    $j = 0
    $aRetArray = _FindPathName($sPath, $sFindFile, $sSearchString)
    If $aRetArray[0] = "0" Then
;~         ReDim $aRetArray[2]
;~         $aRetArray[0] = 1
;~         $aRetArray[1] = "File not found"
        $sEdit = "File not found"
    EndIf
    _UpdateBar(2)
    If $sSearchString <> "" Then
        For $i = 1 To $aRetArray[0]
            $file = FileOpen($aRetArray[$i], 0)
            _UpdateBar(0, $i, $aRetArray[0])
            If $file = -1 Then
            Else
                $text = FileRead($file)
                If StringInStr($text, $sSearchString) > 0 Then
                    $j += 1
                    ReDim $aArayFound[$j + 1]
                    $aArayFound[$j] = $aRetArray[$i]
                    If $j=1 Then GUICtrlSetData($eEdit, "")
                    GUICtrlSetData($eEdit, $aArayFound[$j] & @CRLF,1)
                EndIf
            EndIf
            FileClose($file)
        Next
;~             _ArrayDisplay($aArayFound, "List of file with the String: "&$sSearchString&" found")
        If (Not $j) Then
            $sEdit = "File not found"
            GUICtrlSetData($eEdit, $sEdit)
;~         Else
;~             $sEdit = ""
;~             For $i = 1 To UBound($aArayFound) - 1
;~                 $sEdit &= $aArayFound[$i] & @CRLF
;~             Next
        EndIf
;~         GUICtrlSetData($eEdit, $sEdit)
        _UpdateBar(2)
    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 ;==>_Search

;~ http://www.autoitscript.com/forum/topic/95160-file-searcher
;~ In this forum All files where not Found...
;~ So here is the new way of doing it (Made By Cramaboule)
; 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, $sSearchInFile)
    Local $sSubFolderPath, $iIndex, $aFolders
    GUICtrlSetData($lLabel, $sPath)
    _UpdateBar(1)
    $aFolders = _FileListToArray($sPath, "*", 2)
    $error = @error
    $aFile = _FileListToArray($sPath, $sFindFile, 1)
    If Not (@error) Then ; no files
        For $k = 1 To $aFile[0]
            _ArrayAdd($sRet, $sPath & "\" & $aFile[$k])
            If $sSearchInFile = "" Then
                $flag += 1
                If $flag = 1 Then
                    GUICtrlSetData($eEdit, $sPath & "\" & $aFile[$k] & @CRLF); efface uniquement la première fois !
;~                     ConsoleWrite($sPath& "\"&$aFile[$k]& @CRLF)
                EndIf
                GUICtrlSetData($eEdit, $sPath & "\" & $aFile[$k] & @CRLF, 1)
;~                 ConsoleWrite($sPath& "\"&$aFile[$k]& @CRLF)
            EndIf
        Next
        $sRet[0] = UBound($sRet) - 1
    EndIf
    If Not ($error) Then ; no folders
        For $i = 1 To $aFolders[0]
            $sSubFolderPath = $sPath & "\" & $aFolders[$i]
            _FindPathName($sSubFolderPath, $sFindFile, $sSearchInFile)
        Next
    EndIf
    Return $sRet
EndFunc ;==>_FindPathName

Func _UpdateBar($Update = 0, $actuel = 0, $total = 0)
    If $Update = 1 Then
        $percent += 1
        If $percent >= 100 Then
            $percent = 0
        EndIf
    ElseIf $Update = 0 Then
        $percent = Ceiling(($actuel / $total) * 100)
        GUICtrlSetData($pProgress, $percent)
    ElseIf $Update = 2 Then
        $percent = 100
    EndIf
;~     ConsoleWrite($percent & " " & $actuel & " " & $total & @CRLF)
    GUICtrlSetData($pProgress, $percent)
EndFunc ;==>_UpdateBar

Enjoy.

C.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • dadalt95
      By dadalt95
      Hi!
      I want to get the signal in this website:
      https://binary-signal.com/pt/chart/eurusd
      I have tried using _IEBodyReadText  and some _StringBetween. What happens is that the text are being update every tick and _IEBodyReadText doesn't.
      To perform the update I used  _IEAction($oIE, "refresh") but it's not good because the website block me after some time due too many requests..
      Is there any other way to get this text every tick?
      PS: The text I want to get is WAIT, CALL or PUT.
       
      Here is the code:
      global $oIE = _IECreate ('https://binary-signal.com/pt/chart/eurusd', 0, 1 , 1 , 0) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') ;MsgBox ( 0, "asf", $result[0]) $espera=StringInStr($result[0], "WAIT") $compra=StringInStr($result[0], "CALL") $venda=StringInStr($result[0], "PUT") ;MsgBox($MB_SYSTEMMODAL, "", $espera) $n=0 $c=0 Captar() Func Captar() ;_IENavigate($oIE, "https://binary-signal.com/pt/chart/eurusd") ;MsgBox($MB_SYSTEMMODAL, "", $n) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') If (Not $compra=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "COMPRE") $n=1 $c=$c+1 ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "VENDA") $c=$c+1 $n=1 ;_IEAction($oIE, "refresh") ;MsgBox($MB_SYSTEMMODAL, "", $n) Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() Else ;MsgBox("", "", "ESPERE") $n=0 Sleep(1000) ;_IEAction($oIE, "refresh") Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') Captar() EndIf EndFunc  
    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • lenclstr746
      By lenclstr746
      HELLO GUYS
      I'm a work on a background see and click bot project 
      I can complete it if your help me
      (using imagesearch , gdi+ and  fastfind)
    • dadalt95
      By dadalt95
      Perform a simple google search!
      The script below works fine until fill the google form!
      What I can't find is how to submit the form, tried a couple of ways and none of them worked.

       
      #include <IE.au3> $oIE = _IECreate ("www.google.com") $o_form = _IEFormGetObjByName ($oIE, "f") $o_login = _IEFormElementGetObjByName ($o_form, "q") $username = "80251369" _IEFormElementSetValue ($o_login, $username) $o_numer = _IEGetObjByName($o_form, "btnK") _IEAction ($o_numer, "click")  
      The code runs without any problem.
      I don't know how to proceed!
      Thanks in advance!
    • nacerbaaziz
      By nacerbaaziz
      Hi dears
      how are you? I hope You fine
      I have a question please
      I've created a listView
      It has several columns
      Is there any way  to search for text in an element of this list with text in all columns
      for example
      list view with 2 column
      the first is the file name and the second is the file path
      and i want to search for the item witch Containt the name and the path toGether
      I searched a lot but could not find what I was looking for
      If you do not understand the idea that I'm looking for, I can put an example
      Thanks in advance
×