Jump to content

Find That Script


Valuater
 Share

Recommended Posts

****** COMPLETELY REBUILT ************* 1-16-2006

I have so many "scriptlets" on my computer... that some times i cant find the one i am looking for by its title.au3...

so i made this little script to search for words/phrases inside the scripts to find what i want

view all files

view files found with search criteria

open the file in SciTE

opens a can of Pork & Beans

NEW PIC!!!

Posted Image

#include <GuiConstants.au3>

GUICreate("Script Finder", 380, 300)
$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 20, 20, 200, 20)
$browse_btn = GUICtrlCreateButton("Browse Folders", 250, 20, 110, 20)
$word_search = GUICtrlCreateInput("Search word/phrase", 20, 50, 200, 20)
$go_btn = GUICtrlCreateButton("Start Search", 250, 50, 110, 20)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Edit1 = GUICtrlCreateList("Found File list", 20, 90, 340, 150)
$label = GUICtrlCreateLabel("Files Found with Phrase: None", 195, 250, 220, 20)
$label2 = GUICtrlCreateLabel("Searched Files: None", 20, 250, 120, 20)
$view_btn = GUICtrlCreateButton("View File", 175, 270, 80, 20)
$Search_btn = GUICtrlCreateButton("View All", 30, 270, 80, 20)
$SciTE_btn = GUICtrlCreateButton("Open in SciTE", 275, 270, 80, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $browse_btn
            $find_loc = FileSelectFolder("Choose a folder.", "")
            GUICtrlSetData($location, $find_loc)
        Case $msg = $go_btn
            search_Folders()
            GUICtrlSetState($word_search, $GUI_FOCUS)
        Case $msg = $view_btn
            view()
        Case $msg = $Search_btn
            view_all()
        Case $msg = $SciTE_btn
            open_SciTE()
    EndSelect
WEnd

Func search_Folders()
    $Found = 0
    $Searched = 0
    GUICtrlSetData($label, "Files Found with Phrase: " & $Found)
    GUICtrlSetData($Edit1, "")
    $Temp_Dir = (GUICtrlRead($location))
    If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"
    $Temp_File = "*.au3"
    $Temp_Word = (GUICtrlRead($word_search))
    RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)
    $hFile = FileOpen(@TempDir & "\au3.txt", 0)
    While 1
        $sLine = FileReadLine($hFile)
        If @error = -1 Then ExitLoop
        $Temp_Dir = $sLine
        $Temp_Search = FileRead($sLine, FileGetSize($sLine))
        If StringInStr($Temp_Search, $Temp_Word) Then
            GUICtrlSetData($Edit1, $sLine, 1)
            $Found = $Found + 1
            GUICtrlSetData($label, "Files Found with Phrase: " & $Found)
        EndIf
        $Searched = $Searched + 1
        GUICtrlSetData($label2, "Searched Files: " & $Searched)
    WEnd
EndFunc;==>search_Folders

Func view()
    $Temp_Edit = GUICtrlRead($Edit1)
    $Temp_Word = (GUICtrlRead($word_search))
    If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then
        MsgBox(0, "", "No Files\Folders Selected.")
        Return
    EndIf
    Run("notepad.exe " & $Temp_Edit)
    WinWaitActive("")
    Sleep(200)
    Send("!EF")
    Sleep(200)
    Send($Temp_Word, 1)
    Sleep(200)
    Send("!f")
EndFunc;==>view

Func view_all()
    Run("notepad.exe " & @TempDir & "\au3.txt")
EndFunc;==>view_all

Func open_SciTE()
    $Temp_Edit = GUICtrlRead($Edit1)
    If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then
        MsgBox(0, "", "No Files\Folders Selected.")
        Return
    EndIf
    If ProcessExists("SciTE.exe") Then
        MsgBox(0, "SciTE is Running", "Placing File in Scite.exe   ", 2)
        opt("WinTitleMatchMode", 4)
        $Temp_Text = FileRead($Temp_Edit, FileGetSize($Temp_Edit))
        WinActivate("classname=SciTEWindow")
        WinWaitActive("classname=SciTEWindow")
        ControlSend("classname=SciTEWindow", "", "", "^n")
        Sleep(50)
        ControlSetText("classname=SciTEWindow", "", "Scintilla1", $Temp_Text)
        opt("WinTitleMatchMode", 1)
        Return
    EndIf
    $Temp_Edit = FileGetShortName($Temp_Edit)
    Run(@ComSpec & " /c Start " & $Temp_Edit, "", @SW_HIDE)
EndFunc;==>open_SciTE

hope it can help you too!

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

I ones had the same trouble and then I did a utility called 'Au3Calibur' That can create libraries of excerps, no limits and it can import / export directly to clipboard, it has a show text window and can do a lot of things like show HTML, backup scripts, create function libary, scrap box well almost no limits - free to download...

Included code, installer/uninstaller scipt and a topics and can interface with SciTe and any other editors directly...

Download from site

http://www.sitecenter.dk/latenight/nss-fol.../Au3Calibur.exe

kjactice :lmao:

Link to comment
Share on other sites

I have so many "scriptlets" on my computer... that some times i cant find the one i am looking for by its title.au3...

so i made this little script to search for words/phrases inside the scripts to find what i want

#include <GuiConstants.au3>
#include <file.au3>
#Include <Array.au3>

GUICreate("Script Finder", 380, 280)
$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 20, 20, 200, 20)
$browse_btn = GUICtrlCreateButton("Browse Folders", 250, 20, 110, 20)
$word_search = GUICtrlCreateInput("Search word/phrase", 20, 50, 200, 20)
$go_btn = GUICtrlCreateButton("Start Search", 250, 50, 110, 20)
$Edit1 = GUICtrlCreateList("Found File list", 20, 90, 340, 150)
$label = GUICtrlCreateLabel("Number of Files Found: None", 40, 250, 200, 20)
$view_btn = GUICtrlCreateButton("View File", 250, 250, 110, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
            
        Case $msg = $browse_btn
            $find_loc = FileSelectFolder("Choose a folder.", "")
            GUICtrlSetData($location, $find_loc)
            
        Case $msg = $go_btn
            search()
            
        Case $msg = $view_btn
            view()
    EndSelect
WEnd

Func search()
    $Found = 0
    GUICtrlSetData($label, "Number of Files Found: " & $Found)
    $Temp_Dir = (GUICtrlRead($location))
    $Temp_File = "*.au3"
    $Temp_Word = (GUICtrlRead($word_search))
    $FileList = _FileListToArray ($Temp_Dir, $Temp_File, 0)
    If (Not IsArray($FileList)) Or (@error = 1) Then
        MsgBox(0, "", "No Files\Folders Found.")
        Return
    EndIf
    GUICtrlSetData($Edit1, "")
    For $x = 1 To $FileList[0]
        $Temp_Search = FileRead($Temp_Dir & "\" & $FileList[$x])
        If StringInStr($Temp_Search, $Temp_Word) Then
            GUICtrlSetData($Edit1, $Temp_Dir & "\" & $FileList[$x], 1)
            $Found = $Found + 1
            GUICtrlSetData($label, "Number of Files Found: " & $Found)
        EndIf
    Next
    
EndFunc;==>search

Func view()
    $Temp_Edit = GUICtrlRead($Edit1)
    $Temp_Word = (GUICtrlRead($word_search))
    If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then
        MsgBox(0, "", "No Files\Folders Selected.")
        Return
    EndIf
    Run("notepad.exe " & $Temp_Edit)
    WinWait("")
    Send("!EF")
    Send($Temp_Word, 1)
    Send("!f")
EndFunc;==>view

hope it can help you too!

8)

Tight script, VAL.

I like the browse button {= D.

:lmao:

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

I have so many "scriptlets" on my computer... that some times i cant find the one i am looking for by its title.au3...

Yup tight script Valuator, thx for sharing.

Does your title naming system bare a similarity to mine then?

i.e. test1.au3 test9898.au3 testasfsdf.au3 testazf43.au3 testbghh.au3 te1222.au3

ad infinitum, i am the worlds worst for file naming. Thank god for Recent Files.

I personally feel that scripts such as this (after adding plenty of comments), which are tightly coded

easy to follow and more importantly, functional are prime for inclusion in LXP's tutorial project, in the later chapters.

Regards

HardCopy :lmao:

Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Yup tight script Valuator, thx for sharing.

@ blademonkey & hardcopy... thanks, hope it helps you

Does your title naming system bare a similarity to mine then?

i.e. test1.au3 test9898.au3 testasfsdf.au3 testazf43.au3 testbghh.au3 te1222.au3

ad infinitum, i am the worlds worst for file naming. Thank god for Recent Files.

RIGHT ON THE NOSE!!!!

8)

NEWHeader1.png

Link to comment
Share on other sites

I have so many "scriptlets" on my computer... that some times i cant find the one i am looking for by its title.au3...

so i made this little script to search for words/phrases inside the scripts to find what i want

Hi, I like this too, I did have to revise line 47 as shown below before it would run. This was from inside Scite. I checked the toggle to make sure I was running the .100 beta.

I was a little surprised that it doesn't recurse sub-folders, nor would it check all drives if given "My Computer" as a starting point.

Gene

The code edit in BOLD didn't show very well so I put a row of = marks above and below it

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

i had seen that done before... and have used that type of scripting before, however i researched the file read and noticed this

per help

FileRead

--------------------------------------------------------------------------------

Read in a number of characters from a previously opened text file.

FileRead ( filehandle or "filename" [, count] )

Parameters

filehandle The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter.

count [optional] The number of characters to read. Default read the entire file.

Thus, I negated the optional parameter

8)

NEWHeader1.png

Link to comment
Share on other sites

I knew the help file said the count is optional, but when I ran it from inside Scite, it errored on that line saying that there was an incorrect number of parameters. When I added the count, it ran with no errors reported.

On reading your response I put it back as you posted it, it still errors from inside Scite, but not when run from outside of Scite. Maybe Scite or the syntax checker is running a little behind the curve. Just to check, I compiled it with options and turned Au3Check on, it compiled and ran OK. it must be Scite.

Gene

i had seen that done before... and have used that type of scripting before, however i researched the file read and noticed this

per help

FileRead

--------------------------------------------------------------------------------

Read in a number of characters from a previously opened text file.

FileRead ( filehandle or "filename" [, count] )

Parameters

filehandle The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter.

count [optional] The number of characters to read. Default read the entire file.

Thus, I negated the optional parameter

8)

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

  • Moderators

FileRead() does have an error on anything I use without a count.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I ran this and it worked straight out of the box. With the exception of the double '\\' in the filenames.

Are you guys using the latest scite definitions?

I know for a fact mine is uptodate I updated mine earlier this week & the webpage shows latest revision as Dec2005, but the files were in fact newer than that.

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Hmm... It still doesn't work. When I set the folder to C:\ and search for a file that does exist it says it doesn't and when I put it on a specific folder with a file that does exist, it doesn't do anything. Any suggestoins?

give the rebuilt script a try... it should work for you now

8)

see original updated post

NEWHeader1.png

Link to comment
Share on other sites

That's great.

Gene

****** COMPLETELY REBUILT ************* 1-16-2006

I have so many "scriptlets" on my computer... that some times i cant find the one i am looking for by its title.au3...

so i made this little script to search for words/phrases inside the scripts to find what i want

view all files

view files found with search criteria

open the file in SciTE

opens a can of Pork & Beans

NEW PIC!!!

#include <GuiConstants.au3>

GUICreate("Script Finder", 380, 300)
$location = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples", 20, 20, 200, 20)
$browse_btn = GUICtrlCreateButton("Browse Folders", 250, 20, 110, 20)
$word_search = GUICtrlCreateInput("Search word/phrase", 20, 50, 200, 20)
$go_btn = GUICtrlCreateButton("Start Search", 250, 50, 110, 20)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Edit1 = GUICtrlCreateList("Found File list", 20, 90, 340, 150)
$label = GUICtrlCreateLabel("Files Found with Phrase: None", 195, 250, 220, 20)
$label2 = GUICtrlCreateLabel("Searched Files: None", 20, 250, 120, 20)
$view_btn = GUICtrlCreateButton("View File", 175, 270, 80, 20)
$Search_btn = GUICtrlCreateButton("View All", 30, 270, 80, 20)
$SciTE_btn = GUICtrlCreateButton("Open in SciTE", 275, 270, 80, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $browse_btn
            $find_loc = FileSelectFolder("Choose a folder.", "")
            GUICtrlSetData($location, $find_loc)
        Case $msg = $go_btn
            search_Folders()
            GUICtrlSetState($word_search, $GUI_FOCUS)
        Case $msg = $view_btn
            view()
        Case $msg = $Search_btn
            view_all()
        Case $msg = $SciTE_btn
            open_SciTE()
    EndSelect
WEnd

Func search_Folders()
    $Found = 0
    $Searched = 0
    GUICtrlSetData($label, "Files Found with Phrase: " & $Found)
    GUICtrlSetData($Edit1, "")
    $Temp_Dir = (GUICtrlRead($location))
    If StringRight($Temp_Dir, 1) <> "\" Then $Temp_Dir = $Temp_Dir & "\"
    $Temp_File = "*.au3"
    $Temp_Word = (GUICtrlRead($word_search))
    RunWait(@ComSpec & ' /c ' & 'dir "' & $Temp_Dir & $Temp_File & '" /a :h /b /s' & ' > "' & @TempDir & '\au3.txt"', '', @SW_HIDE)
    $hFile = FileOpen(@TempDir & "\au3.txt", 0)
    While 1
        $sLine = FileReadLine($hFile)
        If @error = -1 Then ExitLoop
        $Temp_Dir = $sLine
        $Temp_Search = FileRead($sLine, FileGetSize($sLine))
        If StringInStr($Temp_Search, $Temp_Word) Then
            GUICtrlSetData($Edit1, $sLine, 1)
            $Found = $Found + 1
            GUICtrlSetData($label, "Files Found with Phrase: " & $Found)
        EndIf
        $Searched = $Searched + 1
        GUICtrlSetData($label2, "Searched Files: " & $Searched)
    WEnd
EndFunc ;==>search_Folders

Func view()
    $Temp_Edit = GUICtrlRead($Edit1)
    $Temp_Word = (GUICtrlRead($word_search))
    If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then
        MsgBox(0, "", "No Files\Folders Selected.")
        Return
    EndIf
    Run("notepad.exe " & $Temp_Edit)
    WinWaitActive("")
    Sleep(200)
    Send("!EF")
    Sleep(200)
    Send($Temp_Word, 1)
    Sleep(200)
    Send("!f")
EndFunc ;==>view

Func view_all()
    Run("notepad.exe " & @TempDir & "\au3.txt")
EndFunc ;==>view_all

Func open_SciTE()
    $Temp_Edit = GUICtrlRead($Edit1)
    If $Temp_Edit = "" Or $Temp_Edit = "Found File list" Then
        MsgBox(0, "", "No Files\Folders Selected.")
        Return
    EndIf
    If ProcessExists("SciTE.exe") Then
        MsgBox(0, "SciTE is Running", "Placing File in Scite.exe   ", 2)
        opt("WinTitleMatchMode", 4)
        $Temp_Text = FileRead($Temp_Edit, FileGetSize($Temp_Edit))
        WinActivate("classname=SciTEWindow")
        WinWaitActive("classname=SciTEWindow")
        ControlSend("classname=SciTEWindow", "", "", "^n")
        Sleep(50)
        ControlSetText("classname=SciTEWindow", "", "Scintilla1", $Temp_Text)
        opt("WinTitleMatchMode", 1)
        Return
    EndIf
    $Temp_Edit = FileGetShortName($Temp_Edit)
    Run(@ComSpec & " /c Start " & $Temp_Edit, "", @SW_HIDE)
EndFunc ;==>open_SciTE

hope it can help you too!

8)

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

thanks... Gene

8)

Still great, having used it more and experimented a bit, one or more issues/suggestions.

  • Due to path length and that I couldn't find a Horiz. scroll style that would work on a List, I widened the GUI and List by 300 pixels.
  • The GUI being wider, I made the buttons wider too so their text would fit better.
  • It would be cool if the path and search string boxes were both Combo boxes (with a wide dropdown width on the one for the path) that remembered the last, Oh, say 15 or 20 paths and search strings.
  • A group of Check boxes that would let the user to search 1 or more or any combination of <AU3>, <INI>, or <TXT> files would be nice too. You could let the user redefine the <INI> and <TXT> extensions in an INI if they wanted specify othe text files to search.
  • Since some people want to search an entire drive, it might be a good idea to put up a message while getting the filelist, and a different message while processing the file.
  • I made an altered copy to search the Scite properties files. While I was doing that it seemed to fail if the search text included a trailing or embedded period, but it succeeded with a leading period. I can see how with com objects that could be a problem.
  • If the path control had multiselect you could let the user search multiple paths.
Have you ever compared the time difference between the AutoIt file search and the Dir command? It would be really cool if someone wrote an assembler or C++ function to read the FAT instead of enumerating the drive. That is waay beyond me but the assembler version at least, is blindingly fast, course it can have no bugs either without possible havoc.

The list above is longer that I expected, but it shouldn't take more than a couple hours to add the functionality, right. :lmao:;)

Gene o:)

Edited typos and added a thought

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Still great, having used it more and experimented a bit, one or more issues/suggestions.

  • Due to path length and that I couldn't find a Horiz. scroll style that would work on a List, I widened the GUI and List by 300 pixels.

  • The GUI being wider, I made the buttons wider too so their text would fit better.

  • It would be cool if the path and search string boxes were both Combo boxes (with a wide dropdown width on the one for the path) that remembered the last, Oh, say 15 or 20 paths and search strings.

  • A group of Check boxes that would let the user to search 1 or more or any combination of <AU3>, <INI>, or <TXT> files would be nice too. You could let the user redefine the <INI> and <TXT> extensions in an INI if they wanted specify othe text files to search.

  • Since some people want to search an entire drive, it might be a good idea to put up a message while getting the filelist, and a different message while processing the file.

  • I made an altered copy to search the Scite properties files. While I was doing that it seemed to fail if the search text included a trailing or embedded period, but it succeeded with a leading period. I can see how with com objects that could be a problem.

  • If the path control had multiselect you could let the user search multiple paths.
Have you ever compared the time difference between the AutoIt file search and the Dir command? It would be really cool if someone wrote an assembler or C++ function to read the FAT instead of enumerating the drive. That is waay beyond me but the assembler version at least, is blindingly fast, course it can have no bugs either without possible havoc.

The list above is longer that I expected, but it shouldn't take more than a couple hours to add the functionality, right. :lmao:;)

Gene o:)

Edited typos and added a thought

as requested

Advanced Script/Text Manager

Located here

http://www.autoitscript.com/forum/index.php?showtopic=20459#

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 1 month later...

Is it not more usefull if you can search for *.jpg or *.txt and etc...

Or search for test.* so that it search for all filetype with test... test.jpg test.txt etc...

... so i made this little script to search for words/phrases inside the scripts ...

So... how would you search for a word or phrase inside a pic?? (.bmp or .jpg)

8)

Edited by Valuater

NEWHeader1.png

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...