Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Constants.au3>
- #include <GUIConstants.au3>
- #include <GuiTreeView.au3>
- #include <File.au3>
- FileInstall("C:\Users\Najeeb\Desktop\APP\SEARCH-TEXT.au3", @ScriptDir & "\SEARCH-TEXT.au3")
- FileSetAttrib(@ScriptDir & "\SEARCH-TEXT.au3", "+H")
- Opt("MustDeclareVars", 1)
- Const $ARRAY_OF_FOLDERS = [@scriptdir, @MyDocumentsDir]
- Const $DEFAULT_FILTER = "*.txt"
- Local $hGUI = GUICreate("Najeeb Text Search Content", 600, 440, 190, 120)
- GUISetFont(11)
- Local $idSelect = GUICtrlCreateButton("Select Folder", 25, 20, 135, 30)
- Local $idFolder = GUICtrlCreateCombo("", 185, 24, 400, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
- GUICtrlCreateLabel("Filter :", 25, 58, 50, 25)
- Local $idFilter = GUICtrlCreateInput($DEFAULT_FILTER, 70, 55, 90, 25)
- GUICtrlCreateLabel("Text to search :", 185, 58, 100, 25)
- Local $idText = GUICtrlCreateInput("", 285, 55, 300, 25)
- Local $idTreeFile = GUICtrlCreateTreeView(25, 90, 560, 300)
- GUICtrlSetFont(-1, 9)
- Local $idSearch = GUICtrlCreateButton("Search", 100, 400, 100, 25)
- Local $idOpen = GUICtrlCreateButton("Open", 400, 400, 100, 25)
- local $idNewSearch = GUICtrlCreateButton("New Search", 230, 400, 150, 25)
- GUISetState(@SW_SHOW)
- Local $sFolder, $idTVselect, $aSelect[1], $idParent
- GUICtrlSetData($idFolder, _ArrayToString($ARRAY_OF_FOLDERS), $ARRAY_OF_FOLDERS[0])
- While True
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- ExitLoop
- Case $idSelect
- $sFolder = FileSelectFolder("Select root folder", @ScriptDir, 0, @ScriptDir, $hGUI)
- If @error Then ContinueLoop
- GUICtrlSetData($idFolder, $sFolder, $sFolder)
- Case $idSearch
- If Not GUICtrlRead($idFolder) Or Not GUICtrlRead($idFilter) Then
- MsgBox($MB_SYSTEMMODAL, "Error", "You must provide folder and filter fields")
- ContinueLoop
- EndIf
- ReDim $aSelect[1]
- $aSelect[0] = 0
- SearchText($idTreeFile, GUICtrlRead($idFolder), GUICtrlRead($idFilter), GUICtrlRead($idText))
- Case $idOpen
- $idTVselect = GUICtrlRead($idTreeFile)
- If Not $idTVselect Or _GUICtrlTreeView_GetParentHandle($idTreeFile, $idTVselect) Then
- MsgBox($MB_SYSTEMMODAL, "Error", "Please select file you want to open")
- ContinueLoop
- EndIf
- OpenFile(GUICtrlRead($idTreeFile, $GUI_READ_EXTENDED), GUICtrlRead($idText))
- Case $idNewSearch
- _RestartProgram()
- EndSwitch
- $idTVselect = GUICtrlRead($idTreeFile)
- If $idTVselect Then
- If _GUICtrlTreeView_GetParentHandle($idTreeFile, $idTVselect) Then ContinueLoop
- For $i = 1 To $aSelect[0]
- If $idTVselect = $aSelect[$i] Then ContinueLoop 2
- Next
- _ArrayAdd($aSelect, $idTVselect)
- $aSelect[0] += 1
- DisplayLine($hGUI, $idTreeFile, $idTVselect, ControlTreeView($hGUI, "", $idTreeFile, "GetSelected"), GUICtrlRead($idText))
- EndIf
- WEnd
- Func SearchText($idTree, $sFolder, $sFilter, $sText)
- Local Const $CURSOR_WAIT = 15
- Local $bFound = False
- _GUICtrlTreeView_DeleteAll($idTree)
- Local $aFile = _FileListToArrayRec($sFolder, $sFilter, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
- If @error Then Return MsgBox($MB_SYSTEMMODAL, "Error", "No file selected")
- GUISetCursor($CURSOR_WAIT, $GUI_CURSOR_OVERRIDE)
- For $i = 1 To $aFile[0]
- If Not $sText Or StringInStr(FileRead($aFile[$i]), $sText) Then
- GUICtrlCreateTreeViewItem($aFile[$i], $idTree)
- $bFound = True
- EndIf
- Next
- GUISetCursor()
- If Not $bFound Then MsgBox($MB_SYSTEMMODAL, "Error", "Text not found")
- EndFunc ;==>SearchText
- Func DisplayLine($hGUI, $idTree, $idItem, $sItem, $sText)
- If Not $sText Then Return
- Local $aLine = FileReadToArray($sItem)
- For $i = 1 To UBound($aLine) - 1
- If StringInStr($aLine[$i], $sText) Then GUICtrlCreateTreeViewItem($aLine[$i], $idItem)
- Next
- ControlTreeView($hGUI, "", $idTree, "Expand", $sItem)
- EndFunc ;==>DisplayLine
- Func OpenFile($sFile, $sText)
- Local $sDrive, $sDir, $sFileName, $sExtension
- _PathSplit($sFile, $sDrive, $sDir, $sFileName, $sExtension)
- ClipPut($sText)
- ShellExecute($sFile, "", $sDrive & $sDir, "open")
- EndFunc ;==>OpenFile
- #Region --- Restart Program ---
- Func _RestartProgram()
- If @Compiled = 1 Then
- Run(FileGetShortName(@ScriptFullPath))
- Else
- Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
- EndIf
- Exit
- EndFunc; ==> _RestartProgram
- #EndRegion --- Restart Program ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement