Jump to content

File search


BananaFredSoft
 Share

Recommended Posts

This is a simple file search program. You can choose which folder to index, and then add more folders to the index easily.

Suggestions/comments/criticism appreciated :)

Update 10-6-07: Added Update Index and some other stuff

_FileListToArrayNew2g.au3 download

#include <File.au3>
#include <Array.au3>
#include <_FileListToArrayNew2g.au3>
#include <GUIConstants.au3>
#include <IE.au3>
#include <GuiListView.au3>
Opt("TrayAutoPause", 0)
Opt("RunErrorsFatal", 0)
$tsearch = TrayCreateItem("Search")
$im = TrayCreateMenu("Indexing")
$tindex = TrayCreateItem("Add folder to index", $im)
$tdeleteindex = TrayCreateItem("Delete index", $im)
$treindex  = TrayCreateItem("Re-Index", $im)
$Buttonrefine = "null"
HotKeySet("^!s", "Search")
$searcharray = _ArrayCreate(0)
$file = _ArrayCreate("")
_FileReadToArray(@ScriptDir & "\FileList.data", $file)
If FileExists(@ScriptDir & "\FileList.data") = 0 Then
    $time = TimerInit()
    $textfile = FileOpen(@ScriptDir & "\FileList.data", 0 + 2)
    $dirtoindex = FileSelectFolder("Select folder to index", "")
    $file = _FileListToArray3($dirtoindex, "*", 1, 1)
    For $i = 1 To $file[0]
        FileWriteLine($textfile, $file[$i])
    Next
    IniWrite(@ScriptDir & "\FileList2.data", "Indexed Folders", IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", 0) + 1, $dirtoindex)
    IniWrite(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", 0) + 1)
    $time = TimerDiff($time)
    MsgBox(0, "Indexing", "Indexing complete. " & $file[0] & " files were indexed. Indexing took " & Round($time / 1000) & " seconds.")
    If MsgBox(4, "Run on startup", "Would you like BananaSearch to run on logon?") = 6 Then
        FileCreateShortcut(@ScriptFullPath, @StartupDir & "\BananaSearch.lnk")
    EndIf
    $file = _ArrayCreate("")
    _FileReadToArray(@ScriptDir & "\FileList.data", $file)
EndIf
While 1
    $t = TrayGetMsg()
    If $t = $tsearch Then
        Search()
    ElseIf $t = $tindex Then
        $time = TimerInit()
        $textfile = FileOpen(@ScriptDir & "\FileList.data", 0 + 1)
        $dirtoindex = FileSelectFolder("Select folder to index", "")
        $file = _FileListToArray3($dirtoindex, "*", 1, 1)
        For $i = 1 To $file[0]
            FileWriteLine($textfile, $file[$i])
        Next
        IniWrite(@ScriptDir & "\FileList2.data", "Indexed Folders", IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", 0) + 1, $dirtoindex)
        IniWrite(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", 0) + 1)
        $time = TimerDiff($time)
        MsgBox(0, "Indexing", "Indexing complete. " & $file[0] & " files were indexed. Indexing took " & Round($time / 1000) & " seconds.")
        $file = _ArrayCreate("")
        _FileReadToArray(@ScriptDir & "\FileList.data", $file)
    ElseIf $t = $tdeleteindex Then
        If MsgBox(4, "Delete Index", "Would you like to delete your index?") = 6 Then
            FileDelete(@ScriptDir & "\FileList.data")
            MsgBox(0, "Delete Index", "Index deleted.")
        EndIf
    ElseIf $t = $treindex Then
        If MsgBox(4, "Re-index", "Would you like to update the index of the folders you had indexed before?") = 6 Then
            FileDelete(@ScriptDir & "\FileList.data")
            $time = TimerInit()
            $textfile = FileOpen(@ScriptDir & "\FileList.data", 0 + 2)
            For $h = 1 To IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", "NUM", 0)
                $dirtoindex = IniRead(@ScriptDir & "\FileList2.data", "Indexed Folders", $h, "")
                $file = _FileListToArray3($dirtoindex, "*", 1, 1)
                For $i = 1 To $file[0]
                    FileWriteLine($textfile, $file[$i])
                Next
            Next
            $time = TimerDiff($time)
            MsgBox(0, "Indexing", "Index update complete. " & $file[0] & " files were indexed. Indexing took " & Round($time / 1000) & " seconds.")
            $file = _ArrayCreate("")
            _FileReadToArray(@ScriptDir & "\FileList.data", $file)
        EndIf
    EndIf
WEnd
Func Search ()
    $searcharray = _ArrayCreate(0)
    $search = InputBox("Search", "Search for a file.")
    $time2 = TimerInit()
    For $i = 1 To $file[0]
        If StringInStr($file[$i], $search) Then
            _ArrayAdd($searcharray, $file[$i])
            $searcharray[0] += 1
        EndIf
    Next
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Results", 444, 426, 193, 115, $WS_SIZEBOX + $WS_MINIMIZEBOX)
    $ListView1 = GUICtrlCreateListView("", 8, 8, 425, 297)
    GUICtrlSetResizing(-1, 3)
    _GUICtrlListViewInsertColumn($ListView1, 0, "File", 0, 415)
    GUICtrlSetResizing(-1, 1)
    For $i = 1 To $searcharray[0]
        GUICtrlCreateListViewItem($searcharray[$i], $ListView1)
    Next
    $Button1 = GUICtrlCreateButton("Go!", 8, 312, 100, 17, 0)
    $Button2 = GUICtrlCreateButton("Navigate", 120, 312, 100, 17, 0)
    $refine = GUICtrlCreateButton("Refine Search", 240, 312, 100, 17, 0)
    $size = GUICtrlCreateLabel("", 20, 339, 300)
    $searchtime = GUICtrlCreateLabel(Round(TimerDiff($time2) / 1000, 2) & " seconds", 20, 359, 200)
    $filenumber = GUICtrlCreateLabel($searcharray[0] & " results.", 20, 379, 200)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $now = ""
    While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[0]
            Case 0
                
            Case $GUI_EVENT_CLOSE
                If $nMsg[1] = $Form1 Then
                    GUIDelete($Form1)
                    ExitLoop
                Else
                    GUIDelete($nMsg[1])
                EndIf
            Case $refine
                #Region ### START Koda GUI section ### Form=
                $Formrefine = GUICreate("Refine Search", 502, 121, 193, 115)
                $Label1 = GUICtrlCreateLabel("Search:", 8, 10, 41, 17)
                $Label2 = GUICtrlCreateLabel("Directory to search in:", 8, 35, 107, 17)
                $Input1 = GUICtrlCreateInput($search, 56, 8, 441, 21)
                $Input2 = GUICtrlCreateInput("", 120, 32, 377, 21)
                $Label3 = GUICtrlCreateLabel("Exclude:", 8, 58, 45, 17)
                $Input3 = GUICtrlCreateInput("", 56, 56, 441, 21)
                $Buttonrefine = GUICtrlCreateButton("Search", 8, 88, 489, 25, 0)
                GUISetState(@SW_SHOW)
                #EndRegion ### END Koda GUI section ###
            Case $Button1
                ShellExecute(StringReplace(GUICtrlRead(GUICtrlRead($ListView1)), "|", ""))
            Case $Button2
                _IECreate(getdir(GUICtrlRead(GUICtrlRead($ListView1))))
            Case $Buttonrefine
                _GUICtrlListViewDeleteAllItems($ListView1)
                $searcharray = _ArrayCreate(0)
                $time2 = TimerInit()
                For $i = 1 To $file[0]
                    If BitAND(StringInStr($file[$i], GUICtrlRead($Input1)), StringInStr($file[$i], GUICtrlRead($Input3)) = 0, StringLeft($file[$i], StringLen(GUICtrlRead($Input2))) = GUICtrlRead($Input2)) Then
                        _ArrayAdd($searcharray, $file[$i])
                        $searcharray[0] += 1
                        GUICtrlCreateListViewItem($file[$i], $ListView1)
                    EndIf
                Next
                GUICtrlSetData($searchtime, Round(TimerDiff($time2) / 1000, 2) & " seconds")
                GUICtrlSetData($filenumber, $searcharray[0] & " results.")
                GUIDelete($Formrefine)
        EndSwitch
        If GUICtrlRead($ListView1) <> $now Then
            GUICtrlSetData($size, FileGetSize(StringReplace(GUICtrlRead(GUICtrlRead($ListView1)), "|", "")) & " bytes")
            $now = GUICtrlRead($ListView1)
        EndIf
    WEnd
EndFunc ;==>Search
Func getdir($filename)
    $split = StringSplit($filename, "\")
    If Not @error Then
        $dir = ""
        $num = 1
        Do
            $dir &= $split[$num] & "\"
            $num += 1
        Until $num = $split[0]
        Return $dir
    EndIf
    Return 0
EndFunc   ;==>getdir
Edited by BananaFredSoft
Link to comment
Share on other sites

Link to comment
Share on other sites

@BananaFredSoft

I think that it's better to use what is already there on the system, rather than to reinvent the wheel. :)

MS Indexing Service

This functionality will not only index the names of but also the content.

regards,

ptrex

I can always try, can't I? ;)

Link to comment
Share on other sites

  • 5 weeks later...

How do you use this ? I try to build and after I started the .exe.. but nothing happens.

Also, it has some UI ? And some options when and how to make the index ?

New update!

I hope it works better for you.

Link to comment
Share on other sites

  • 7 months later...

_FileListToArrayNew2g.au3 download

Sorry, some required files are missing, if you intended to view a topic, it's possible that it's been moved or deleted. Please go back and try again.

Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...

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