BananaFredSoft Posted September 2, 2007 Posted September 2, 2007 The problem I am having with this script is that when you search for something, and then close the GUI, and then search for something again, the search results from the previous search are still there. Thanks in advance!_FileListToArrayNew2g.au3 download hereexpandcollapse popup#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) 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) $file = _FileListToArray3(FileSelectFolder("Select folder to index", ""), "*", 1, 1) For $i = 1 To $file[0] FileWriteLine($textfile, $file[$i]) Next $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) EndIf While 1 $t = TrayGetMsg() If $t = $tsearch Then Search() ElseIf $t = $tindex Then $time = TimerInit() $textfile = FileOpen(@ScriptDir & "\FileList.data", 0 + 1) $file = _FileListToArray3(FileSelectFolder("Select folder to index", ""), "*", 1, 1) For $i = 1 To $file[0] FileWriteLine($textfile, $file[$i]) Next $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 EndIf WEnd Func Search () $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, 406, 193, 115) $ListView1 = GUICtrlCreateListView("", 8, 8, 425, 297) _GUICtrlListViewInsertColumn($ListView1, 0, "File", 0, 415) 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) $size = GUICtrlCreateLabel("", 20, 339, 300) $searchtime = GUICtrlCreateLabel(Round(TimerDiff($time2) / 1000, 2) & " seconds", 20, 359) $filenumber = GUICtrlCreateLabel($searcharray[0] & " results.", 20, 379) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $now = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form1) ExitLoop Case $Button1 ShellExecute(StringReplace(GUICtrlRead(GUICtrlRead($ListView1)), "|", "")) Case $Button2 _IECreate(getdir(GUICtrlRead(GUICtrlRead($ListView1)))) 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 -ColinSite:www.bananafredsoft.comStuff:Simple Text Editor - MediaPlayer - Animator - BananaDB - BananaNotes - Chatta - Filesearch - Excuse GeneratorMy YouTube channel:http://www.youtube.com/user/colipat
Siao Posted September 2, 2007 Posted September 2, 2007 That's because during each search you keep adding new values to $searcharray, which already contains old values too. You need it empty at the start of Search() function. "be smart, drink your wine"
BananaFredSoft Posted September 3, 2007 Author Posted September 3, 2007 That's because during each search you keep adding new values to $searcharray, which already contains old values too.You need it empty at the start of Search() function.Whoops. That was stupid of me. Thanks! -ColinSite:www.bananafredsoft.comStuff:Simple Text Editor - MediaPlayer - Animator - BananaDB - BananaNotes - Chatta - Filesearch - Excuse GeneratorMy YouTube channel:http://www.youtube.com/user/colipat
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now