;SearchEngine.au3 1.5.1.2.Rand3 /Index Engine #region startup ;hides the tray(obviously) ;#NoTrayIcon opt("RunErrorsFatal", 0) ;a small error handler, just gets rid of the ugly autoit error, i hope. Comment it out when debugging ObjEvent("AutoIt.Error", "Error") ;some files to include, not sure which ones i actually still need since i didn't delete them after i got rid of some functions that required them #include #include #include #Include Global $mainGUI Global $indexstatuslabel Global $number Global $filetosave Global $file Global $filesize Global $usercancel Global $drive Global $filearray Global $filetosave = @ScriptDir & "\indexdata.index" Global $searchquierie Global $filetosavehandle Global $filepath Global $DBpath Global $fixeddrives Global $indexoutput Global $indexinput Global $fileoutput Global $filecounter Global $CurrentFile Global $titleindex ;used GUI builder created by CyberSlug $mainGUI = GUICreate("Brian's Search Engine", 600, 300, (@DesktopWidth - 600) / 2, (@DesktopHeight - 300) / 2) ;$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $lblasdf = GUICtrlCreateGroup("Search", 10, 60, 580, 110) $Label_2 = GUICtrlCreateLabel("Brian's Search Engine", 200, 35, 200, 30, $ES_CENTER) $searchquierieinput = GUICtrlCreateInput("", 250, 90, 310, 20) $Label_4 = GUICtrlCreateLabel("A filename or part of a filename to search for:", 20, 90, 210, 20) $startsearchbutton = GUICtrlCreateButton("Search", 200, 130, 100, 30) $Group_6 = GUICtrlCreateGroup("Indexing", 10, 180, 580, 100) $rebuildindexbutton = GUICtrlCreateButton("Rebuild Index", 260, 200, 80, 30) $rebuildSQLbutton = GUICtrlCreateButton("Rebuild SQL", 260, 240, 80, 30) $helpbutton = GUICtrlCreateButton("Help", 500, 10, 75, 20) $getindextime = GUICtrlCreateButton("Get Index Date",390,220,80,30) GUICtrlSetState($startsearchbutton, $GUI_DEFBUTTON) GUICtrlSetFont($Label_2, 14) GUICtrlCreateLabel("Search for files in:", 20, 133, 100, 30) $fastradio = GUICtrlCreateRadio("Fast Search(Uses all CPU. Can't control GUI)", 310, 120, 250, 25) $slowradio = GUICtrlCreateRadio("Slower Search(Can stop search midway/open files)", 310, 140, 270, 25) GUICtrlSetState($fastradio, $GUI_CHECKED) GUICtrlCreateLabel("Index the files in:", 60, 233, 100, 30) $drivecombo = GUICtrlCreateCombo("All Drives", 110, 130, 70, 30, $CBS_DROPDOWNLIST) $drivecomboindex = GUICtrlCreateCombo("All Drives", 150, 230, 70, 30, $CBS_DROPDOWNLIST) $fixeddrives = DriveGetDrive( "FIXED") $sAlldrives = DriveGetDrive( "ALL") $fixeddrives = $sAlldrives If Not @error Then For $i = 1 To $fixeddrives[0] GUICtrlSetData($drivecombo, StringUpper($fixeddrives[$i]), "All Drives") GUICtrlSetData($drivecomboindex, StringUpper($fixeddrives[$i]), "All Drives") Next EndIf GUISetState() #endregion While 1 ;while loop for the main GUI, the very simple main one that starts up first $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $getindextime $listtodisplay = "" For $count = 1 to $fixeddrives[0] $listtodisplay &= "Index for drive " & StringUpper($fixeddrives[$count]) & " was last updated " $timestamp = FileGetTime(@scriptdir & "\title" & StringTrimRight($fixeddrives[$count],1) & ".index",0) $nonarraytimestamp = "" $nonarraytimestamp = $timestamp[1] & "/" & $timestamp[2] & "/" & $timestamp[0] & " at " & $timestamp[3] & ":" & $timestamp[4] & ":"& $timestamp[5] & @CRLF $listtodisplay &= $nonarraytimestamp Next $listtodisplay = StringTrimRight($listtodisplay,1) MsgBox(64,"Index Files Last Updated:","The following index files were last updated:" & @CRLF & @CRLF & $listtodisplay) Case $msg = $startsearchbutton If GUICtrlRead($searchquierieinput) <> "" Then If GUICtrlRead($fastradio) = $GUI_CHECKED Then Call(StartSearch()) ElseIf GUICtrlRead($slowradio) = $GUI_CHECKED Then Call(StartSearchSlow()) EndIf Else MsgBox(48, "Error", "You didn't enter a search query.") EndIf ;calls the index function to start indexing the computer Case $msg = $rebuildindexbutton Call(IndexingEngine()) Case $msg = $rebuildSQLbutton Call(DBEngine()) Case $msg = $helpbutton Local $helplocation = @ScriptDir & "\help.htm" If Not FileExists($helplocation) Then ;Must Edit this before compile FileInstall("C:\AUTO it Scripts\Search Engine\help.htm", $helplocation) EndIf Run(@ComSpec & " /c " & FileGetShortName($helplocation), "", @SW_HIDE) EndSelect WEnd Func startsearchOld() ;am old function that uses INI, but no longer is used since my program no longer utilizes ini functions ;feel free to look at it ;~ ;MsgBox(4096, "", "Functioncalled") ;~ $searchquierie = GUICtrlRead($searchquierieinput) ;~ $inireadsectionnames = IniReadSectionNames ( $filepath ) ;~ msgbox(0,"INI Sectionnames",$inireadsectionnames[0]) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $i = 1 To $inireadsectionnames[0] ;~ msgbox(0,"", $inireadsectionnames[0]) ;~ $stringsearch = StringInStr ( $inireadsectionnames[$i], $searchquierie ) ;~ If $stringsearch <> 0 Then ;~ $openfilehandle = Fileopen(@scriptdir & "\results.txt",1) ;~ ;Filewriteline(@scriptdir & "\results.txt",$inireadsectionnames[$i]) ;~ $sectionread = IniReadSection( @ScriptDir & "\Drive C.index", $inireadsectionnames[$i]) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ Filewriteline(@scriptdir & "\results.txt",$sectionread[$x][0] & $inireadsectionnames[$i]) ;~ ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next ;~ EndIf ;~ FileClose($openfilehandle) ;~ Endif ;~ ;MsgBox(4096, "", $inireadsectionnames[$i]) ;~ Next ;~ EndIf EndFunc ;==>startsearchOld Func StartSearch() $usercancel = "false" $filecounter = 0 HotKeySet("{Esc}", "Cancel") If Not FileExists(@ScriptDir & "\results.txt") Then _FileCreate(@ScriptDir & "\results.txt") EndIf GUISetState(@SW_HIDE, $mainGUI) $readdrivecombo = GUICtrlRead($drivecombo) $searchquierie = GUICtrlRead($searchquierieinput) $searchGUI = GUICreate("Searching... (Esc cancels)", 800, 600, (@DesktopWidth - 800) / 2, (@DesktopHeight - 600) / 2) $searchlistView = GUICtrlCreateListView("Filename|Location|Size", 10, 10, 790, 570) $statuslabel = GUICtrlCreateLabel("", 10, 580, 790, 20) GUISetState() Local $InFile = '...' Local $OutFile = @ScriptDir & "\results.txt" Local $Search = '...' Local $i = 0 Local $j = 0 Local $searchlistitemarray If $readdrivecombo = "All Drives" Then For $i = 1 To $fixeddrives[0] $filepath = @ScriptDir & "\title" & StringTrimRight($fixeddrives[$i], 1) & ".index" $masterindexpath = @ScriptDir & "\masterindex" & StringTrimRight($fixeddrives[$i], 1) & ".index" Local $InHandle = FileOpen($masterindexpath, 0) If $InHandle = -1 Then MsgBox(48, "No Index File Found", "No index file found for drive " & $fixeddrives[$i] & ". Please rebuild the index. " & @CRLF & @CRLF & "If this is your first time using this search engine, you must build an index. Please select the drive you wish to build the index for on the main screen in the indexing group box. Then click the 'Rebuild Index' button." & @CRLF & @CRLF & "Once the index has been built the search engine should work faster than the explorer search companion. It can take as little as 10 min to build an index, though it will most likely take longer. The time it takes to build an index is determined by how many drives you have and how many files you have.") ;$usercancel = "true" EndIf Local $OutHandle = FileOpen($OutFile, 1) FileWriteLine($OutHandle, "Search for results for '" & $searchquierie & "' on drive " & $fixeddrives[$i] & ".") $current = _GUICtrlListViewGetHotItem ($searchlistView) If $InHandle <> - 1 And $OutFile <> - 1 Then While 1 Local $Line = FileReadLine($InHandle) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop ;~ $Line = StringTrimLeft($Line,1) ;~ $Line = StringTrimRight($Line,2) If $filecounter >= 50 Then GUICtrlSetData($statuslabel, $Line) $filecounter = 0 EndIf $filecounter = $filecounter + 1 If StringInStr($Line, $searchquierie) Then $sectionread = IniReadSection($filepath, $Line) If @error Then Else For $x = 1 To $sectionread[0][0] FileWriteLine($OutFile, $sectionread[$x][0] & $Line) $filesize = $sectionread[$x][1] / 1024 GUICtrlCreateListViewItem($Line & "|" & $sectionread[$x][0] & "|" & Round($filesize, 2) & " KB", $searchlistView) $j = $j + 1 ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) Next EndIf #cs $Stringasarray = StringSplit($Line, "\") $filename = $Stringasarray[$Stringasarray[0]] If StringInStr($filename, $searchquierie) Then FileWriteLine($OutHandle, $Line) ;~ $sectionread = IniReadSection( @ScriptDir & "\Drive C.index", $Line) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ Filewriteline(@scriptdir & "\results.txt",$sectionread[$x][0] & $Line) $filesize = Round(FileGetSize($Line) / 1024, 2) If @error Then $filesize = "?" $j = $j + 1 GUICtrlCreateListViewItem($filename & "|" & StringTrimRight($Line, StringLen($filename)) & "|" & $filesize & " KB", $searchlistView) ;~ $searchlistitemarray[0] = $i ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next EndIf #ce EndIf #cs $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) GUISetState(@SW_SHOW,$mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then ;msgbox("", "Hot Item:" , _GUICtrlListViewGetHotItem ($searchlistView)) $current = _GUICtrlListViewGetHotItem ($searchlistView) ;msgbox(0,"",_GUICtrlListViewGetItemText($searchlistView, $current, 1)) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe " & _GUICtrlListViewGetItemText($searchlistView, $current, 1),"",@SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then ;msgbox("", "Hot Item:" , "None") EndIf EndIf EndSelect #ce WEnd FileClose($InHandle) FileClose($OutHandle) EndIf Next Else $filepath = @ScriptDir & "\title" & StringTrimRight($readdrivecombo, 1) & ".index" $masterindexpath = @ScriptDir & "\masterindex" & StringTrimRight($readdrivecombo, 1) & ".index" Local $InHandle = FileOpen($masterindexpath, 0) If $InHandle = -1 Then MsgBox(48, "No Index File Found", "No index file found for drive " & $readdrivecombo & ". Please rebuild the index. " & @CRLF & @CRLF & "If this is your first time using this search engine, you must build an index. Please select the drive you wish to build the index for on the main screen in the indexing group box. Then click the 'Rebuild Index' button." & @CRLF & @CRLF & "Once the index has been built the search engine should work faster than the explorer search companion. It can take as little as 10 min to build an index, though it will most likely take longer. The time it takes to build an index is determined by how many drives you have and how many files you have.") ;$usercancel = "true" EndIf Local $OutHandle = FileOpen($OutFile, 1) FileWriteLine($OutHandle, "Search for results for '" & $searchquierie & "' on drive " & $readdrivecombo & ".") $current = _GUICtrlListViewGetHotItem ($searchlistView) If $InHandle <> - 1 And $OutFile <> - 1 Then While 1 Local $Line = FileReadLine($InHandle) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop ;~ $Line = StringTrimLeft($Line,1) ;~ $Line = StringTrimRight($Line,2) If $filecounter >= 50 Then GUICtrlSetData($statuslabel, $Line) $filecounter = 0 EndIf $filecounter = $filecounter + 1 If StringInStr($Line, $searchquierie) Then $sectionread = IniReadSection($filepath, $Line) If @error Then Else For $x = 1 To $sectionread[0][0] FileWriteLine($OutFile, $sectionread[$x][0] & $Line) $filesize = $sectionread[$x][1] / 1024 GUICtrlCreateListViewItem($Line & "|" & $sectionread[$x][0] & "|" & Round($filesize, 2) & " KB", $searchlistView) $j = $j + 1 ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) Next EndIf #cs $Stringasarray = StringSplit($Line, "\") $filename = $Stringasarray[$Stringasarray[0]] If StringInStr($filename, $searchquierie) Then FileWriteLine($OutHandle, $Line) ;~ $sectionread = IniReadSection( @ScriptDir & "\Drive C.index", $Line) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ Filewriteline(@scriptdir & "\results.txt",$sectionread[$x][0] & $Line) $filesize = Round(FileGetSize($Line) / 1024, 2) If @error Then $filesize = "?" $j = $j + 1 $searchlistitemarray[$i] = GUICtrlCreateListViewItem($filename & "|" & StringTrimRight($Line, StringLen($filename)) & "|" & $filesize & " KB", $searchlistView) ;~ $searchlistitemarray[0] = $i ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next EndIf #ce EndIf #cs $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) GUISetState(@SW_SHOW,$mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then ;msgbox("", "Hot Item:" , _GUICtrlListViewGetHotItem ($searchlistView)) $current = _GUICtrlListViewGetHotItem ($searchlistView) ;msgbox(0,"",_GUICtrlListViewGetItemText($searchlistView, $current, 1)) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe " & _GUICtrlListViewGetItemText($searchlistView, $current, 1),"",@SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then ;msgbox("", "Hot Item:" , "None") EndIf EndIf EndSelect #ce WEnd FileClose($InHandle) FileClose($OutHandle) EndIf EndIf GUICtrlSetData($statuslabel, "Done! Found " & $j & " files.") WinSetTitle("Searching... (Esc cancels)", "", "Search Results") HotKeySet("{Esc}") While 1 ;~ $current = _GUICtrlListViewGetHotItem ($searchlistView) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) GUISetState(@SW_SHOW, $mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then ;msgbox("", "Hot Item:" , _GUICtrlListViewGetHotItem ($searchlistView)) $current = _GUICtrlListViewGetHotItem ($searchlistView) ;msgbox(0,"",_GUICtrlListViewGetItemText($searchlistView, $current, 1)) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe /select, " & _GUICtrlListViewGetItemText ($searchlistView, $current, 1) & _GUICtrlListViewGetItemText ($searchlistView, $current, 0), "", @SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then ;msgbox("", "Hot Item:" , "None") EndIf EndIf EndSelect WEnd EndFunc ;==>StartSearch Func StartSearchSlow() $usercancel = "false" If Not FileExists(@ScriptDir & "\results.txt") Then _FileCreate(@ScriptDir & "\results.txt") EndIf GUISetState(@SW_HIDE, $mainGUI) $readdrivecombo = GUICtrlRead($drivecombo) $searchquierie = GUICtrlRead($searchquierieinput) $searchGUI = GUICreate("Searching...", 800, 600, (@DesktopWidth - 800) / 2, (@DesktopHeight - 600) / 2) $searchlistView = GUICtrlCreateListView("Filename|Location|Size", 10, 10, 790, 570) $statuslabel = GUICtrlCreateLabel("", 10, 580, 790, 20) GUISetState() Local $InFile = '...' Local $OutFile = @ScriptDir & "\results.txt" Local $Search = '...' Local $i = 0 Local $j = 0 Local $searchlistitemarray If $readdrivecombo = "All Drives" Then For $i = 1 To $fixeddrives[0] $filepath = @ScriptDir & "\title" & StringTrimRight($fixeddrives[$i], 1) & ".index" $masterindexpath = @ScriptDir & "\masterindex" & StringTrimRight($fixeddrives[$i], 1) & ".index" Local $InHandle = FileOpen($masterindexpath, 0) If $InHandle = -1 Then MsgBox(48, "No Index File Found", "No index file found for drive " & $fixeddrives[$i] & ". Please rebuild the index. " & @CRLF & @CRLF & "If this is your first time using this search engine, you must build an index. Please select the drive you wish to build the index for on the main screen in the indexing group box. Then click the 'Rebuild Index' button." & @CRLF & @CRLF & "Once the index has been built the search engine should work faster than the explorer search companion. It can take as little as 10 min to build an index, though it will most likely take longer. The time it takes to build an index is determined by how many drives you have and how many files you have.") ;$usercancel = "true" EndIf Local $OutHandle = FileOpen($OutFile, 1) FileWriteLine($OutHandle, "Search for results for '" & $searchquierie & "' on drive " & $fixeddrives[$i] & ".") $current = _GUICtrlListViewGetHotItem ($searchlistView) If $InHandle <> - 1 And $OutFile <> - 1 Then While 1 Local $Line = FileReadLine($InHandle) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop ;~ $Line = StringTrimLeft($Line,1) ;~ $Line = StringTrimRight($Line,2) If $filecounter >= 50 Then GUICtrlSetData($statuslabel, $Line) $filecounter = 0 EndIf $filecounter = $filecounter + 1 If StringInStr($Line, $searchquierie) Then $sectionread = IniReadSection($filepath, $Line) If @error Then Else For $x = 1 To $sectionread[0][0] FileWriteLine($OutFile, $sectionread[$x][0] & $Line) $filesize = $sectionread[$x][1] / 1024 GUICtrlCreateListViewItem($Line & "|" & $sectionread[$x][0] & "|" & Round($filesize, 2) & " KB", $searchlistView) $j = $j + 1 ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) Next EndIf #cs $Stringasarray = StringSplit($Line, "\") $filename = $Stringasarray[$Stringasarray[0]] If StringInStr($filename, $searchquierie) Then FileWriteLine($OutHandle, $Line) ;~ $sectionread = IniReadSection( @ScriptDir & "\Drive C.index", $Line) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ Filewriteline(@scriptdir & "\results.txt",$sectionread[$x][0] & $Line) $filesize = Round(FileGetSize($Line) / 1024, 2) If @error Then $filesize = "?" $j = $j + 1 GUICtrlCreateListViewItem($filename & "|" & StringTrimRight($Line, StringLen($filename)) & "|" & $filesize & " KB", $searchlistView) ;~ $searchlistitemarray[0] = $i ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next EndIf #ce EndIf $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) $usercancel = "true" GUISetState(@SW_SHOW, $mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then ;msgbox("", "Hot Item:" , _GUICtrlListViewGetHotItem ($searchlistView)) $current = _GUICtrlListViewGetHotItem ($searchlistView) ;msgbox(0,"",_GUICtrlListViewGetItemText($searchlistView, $current, 1)) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe /select, " & _GUICtrlListViewGetItemText ($searchlistView, $current, 1) & _GUICtrlListViewGetItemText ($searchlistView, $current, 0), "", @SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then ;msgbox("", "Hot Item:" , "None") EndIf EndIf EndSelect WEnd FileClose($InHandle) FileClose($OutHandle) EndIf Next Else $filepath = @ScriptDir & "\title" & StringTrimRight($readdrivecombo, 1) & ".index" $masterindexpath = @ScriptDir & "\masterindex" & StringTrimRight($readdrivecombo, 1) & ".index" Local $InHandle = FileOpen($masterindexpath, 0) If $InHandle = -1 Then MsgBox(48, "No Index File Found", "No index file found for drive " & $readdrivecombo & ". Please rebuild the index. " & @CRLF & @CRLF & "If this is your first time using this search engine, you must build an index. Please select the drive you wish to build the index for on the main screen in the indexing group box. Then click the 'Rebuild Index' button." & @CRLF & @CRLF & "Once the index has been built the search engine should work faster than the explorer search companion. It can take as little as 10 min to build an index, though it will most likely take longer. The time it takes to build an index is determined by how many drives you have and how many files you have.") ;$usercancel = "true" EndIf Local $OutHandle = FileOpen($OutFile, 1) FileWriteLine($OutHandle, "Search for results for '" & $searchquierie & "' on drive " & $readdrivecombo & ".") $current = _GUICtrlListViewGetHotItem ($searchlistView) If $InHandle <> - 1 And $OutFile <> - 1 Then While 1 Local $Line = FileReadLine($InHandle) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop ;~ $Line = StringTrimLeft($Line,1) ;~ $Line = StringTrimRight($Line,2) If $filecounter >= 50 Then GUICtrlSetData($statuslabel, $Line) $filecounter = 0 EndIf $filecounter = $filecounter + 1 If StringInStr($Line, $searchquierie) Then $sectionread = IniReadSection($filepath, $Line) If @error Then Else For $x = 1 To $sectionread[0][0] FileWriteLine($OutFile, $sectionread[$x][0] & $Line) $filesize = $sectionread[$x][1] / 1024 GUICtrlCreateListViewItem($Line & "|" & $sectionread[$x][0] & "|" & Round($filesize, 2) & " KB", $searchlistView) $j = $j + 1 ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) Next EndIf #cs $Stringasarray = StringSplit($Line, "\") $filename = $Stringasarray[$Stringasarray[0]] If StringInStr($filename, $searchquierie) Then FileWriteLine($OutHandle, $Line) ;this commented out code was used for the previous search engine that used an ini type index file. ;didn't delete it because it still has great potential since it is much faster than even this current search engine ;the only problem was that the indexing engine would take forever to create ini indexes ;~ $sectionread = IniReadSection( @ScriptDir & "\Drive C.index", $Line) ;~ If @error Then ;~ MsgBox(4096, "", "Error occured, probably no INI file.") ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ Filewriteline(@scriptdir & "\results.txt",$sectionread[$x][0] & $Line) $filesize = Round(FileGetSize($Line) / 1024, 2) If @error Then $filesize = "?" $j = $j + 1 $searchlistitemarray[$i] = GUICtrlCreateListViewItem($filename & "|" & StringTrimRight($Line, StringLen($filename)) & "|" & $filesize & " KB", $searchlistView) ;~ $searchlistitemarray[0] = $i ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next EndIf #ce EndIf $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) $usercancel = "true" GUISetState(@SW_SHOW, $mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then $current = _GUICtrlListViewGetHotItem ($searchlistView) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe /select, " & _GUICtrlListViewGetItemText ($searchlistView, $current, 1) & _GUICtrlListViewGetItemText ($searchlistView, $current, 0), "", @SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then EndIf EndIf EndSelect WEnd FileClose($InHandle) FileClose($OutHandle) EndIf EndIf GUICtrlSetData($statuslabel, "Done! Found " & $j & " files.") WinSetTitle("Searching...", "", "Search Results") HotKeySet("{Esc}") While 1 If $usercancel = "true" Then ExitLoop $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($searchGUI) If $usercancel = "true" Then ExitLoop GUISetState(@SW_SHOW, $mainGUI) ExitLoop EndSelect Select Case $msg = $GUI_EVENT_PRIMARYDOWN $pos = GUIGetCursorInfo() If ($pos[4] == $searchlistView) Then If ($current <> _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then $current = _GUICtrlListViewGetHotItem ($searchlistView) ElseIf ($current = _GUICtrlListViewGetHotItem ($searchlistView) And _GUICtrlListViewGetHotItem ($searchlistView) >= 0) Then Run("explorer.exe /select, " & _GUICtrlListViewGetItemText ($searchlistView, $current, 1) & _GUICtrlListViewGetItemText ($searchlistView, $current, 0), "", @SW_MAXIMIZE) ElseIf (_GUICtrlListViewGetHotItem ($searchlistView == -1)) Then EndIf EndIf EndSelect WEnd EndFunc ;==>StartSearchSlow ;~ Func ReadSectionnames() ;~ ;~ If Not FileExists(@ScriptDir & "\results.txt") Then ;~ ;~ _FileCreate(@ScriptDir & "\results.txt") ;~ ;~ EndIf ;~ ;~ GUISetState(@SW_HIDE, $mainGUI) ;~ ;~ $searchquierie = GUICtrlRead($searchquierieinput) ;~ ;~ $searchGUI = GUICreate("Searching...", 800, 600, (@DesktopWidth - 800) / 2, (@DesktopHeight - 600) / 2) ;~ ;~ $searchlistView = GUICtrlCreateListView("Filename|Location|Size", 10, 10, 790, 570) ;~ ;~ $statuslabel = GUICtrlCreateLabel("", 10, 580, 790, 20) ;~ ;~ GUISetState() ;~ ;~ $lines = _FileCountLines($filepath) ;~ ;~ ;~ ;~ For $Line = 1 To $lines ;~ ;~ ;$msg = GUIGetMsg() ;~ ;~ $ReadLineString = FileReadLine($filepath, $Line) ;~ ;~ ;~ ;~ ;GUISetState() ;~ ;~ ;msgbox(0,"",$ReadLineString) ;~ ;~ ;msgbox(0,"stringtrimedleft",StringTrimLeft($readlinestring,stringlen($readlinestring)-1)) ;~ ;~ ;msgbox(0,"stringtrimmedright",StringTrimRight($readlinestring,stringlen($readlinestring)-1)) ;~ ;~ If StringLeft($ReadLineString, 1) = "[" And StringRight($ReadLineString, 1) = "]" Then ;~ If StringLeft($ReadLineString, 1) = "[" Then ;~ ;~ ;~ ;~ $ReadLineString = StringTrimRight($ReadLineString, 2) ;~ ;~ ;~ ;~ $ReadLineString = StringTrimLeft($ReadLineString, 1) ;~ ;~ ;~ ;~ If WinActive("Searching...") Then ;~ ;~ GUICtrlSetData($statuslabel, $ReadLineString) ;~ ;~ EndIf ;~ ;msgbox(0,"string without brackets",$readlinestring) ;~ ;~ $stringsearch = StringInStr($ReadLineString, $searchquierie) ;~ ;~ ;~ ;~ ;~ If $stringsearch <> 0 Then ;~ ;~ ;~ ;~ $openfilehandle = FileOpen(@ScriptDir & "\results.txt", 1) ;~ ;~ ;Filewriteline(@scriptdir & "\results.txt",$inireadsectionnames[$i]) ;~ ;~ $sectionread = IniReadSection(@ScriptDir & "\Drive C.index", $ReadLineString) ;~ ;~ If @error Then ;~ ;~ Else ;~ For $x = 1 To $sectionread[0][0] ;~ FileWriteLine(@ScriptDir & "\results.txt", $sectionread[$x][0] & $ReadLineString) ;~ ;~ ;~ ;~ GUICtrlCreateListViewItem($ReadLineString & "|" & $sectionread[$x][0] & "|" & Round($filesize, 2) & " KB", $searchlistView) ;~ ;~ ;MsgBox(4096, "", "Key: " & $sectionread[$i][0] & @CRLF & "Value: " & $sectionread[$i][1]) ;~ Next ;~ ;~ EndIf ;~ ;~ FileClose($openfilehandle) ;~ ;~ EndIf ;~ ;~ EndIf ;~ ;~ EndIf ;~ Next ;~ ;~ While 1 ;~ ;~ $msg = GUIGetMsg() ;~ ;~ If $msg = $GUI_EVENT_CLOSE Then ;~ ;~ GUIDelete($searchGUI) ;~ ;~ GUISetState(@SW_SHOW, $mainGUI) ;~ ;~ ExitLoop ;~ ;~ EndIf ;~ ;~ ;~ WEnd ;~ ;~ ;~ ;~ EndFunc ;==>ReadSectionnames ; an indexing engine i wrote that indexes all files on a computer. It is actually two functions. This is the first indexing engine function Func IndexingEngine() If @Compiled = 1 Then ProcessSetPriority(@ScriptName, 0) EndIf ;makes sure the starting value of the usercancel is set to false, otherwise the indexing engine will shut down before it starts $usercancel = "false" ;sets the output equal to nothing $indexoutput = "" ;set the cancel escape key as escape HotKeySet("{Esc}", "Cancel") ;hide the main GUI since we don't care about it anymore GUISetState(@SW_HIDE, $mainGUI) ;create the indexing GUI that will display data on the current file being indexed $indexingGUI = GUICreate("Indexing... (Esc cancels)", 300, 50, (@DesktopWidth - 300) / 2, (@DesktopHeight - 50) / 2) ;creates a label for the indexing GUI GUICtrlCreateLabel("Indexing. This may take a while. Please Wait...", 30, 1, 250, 25) ;creates another label where the filenames will be stored as it processes the files $indexstatuslabel = GUICtrlCreateLabel("", 20, 25, 280, 20) ;creates the GUI GUISetState() $filecounter = 0 ;reads the combobox to check what drives the user wants indexed $readdrivecomboindex = GUICtrlRead($drivecomboindex) ;check the else on this if statement to get the more commmented version of my engine If $readdrivecomboindex = "All Drives" Then $fixeddrives = DriveGetDrive("FIXED") If Not @error Then ;will loop the engine for every fixed drive on the computer For $i = 1 To $fixeddrives[0] ;~ msgbox("0","All Drives For Loop","The main all drives for loop has been activated. Number of drives is " & $fixeddrives[0] & ". The current drive is drive " & $fixeddrives[$i] & ".",20) $drive = $fixeddrives[$i] $filepath = @ScriptDir & "\title" & StringTrimRight($drive, 1) & ".index" If Not FileExists($filepath) Then _FileCreate($filepath) Else FileMove($filepath, $filepath & ".bak", 1) _FileCreate($filepath) EndIf $Search = FileFindFirstFile($drive & "\*.*") ;msgbox(0,"",$drive & "\*.*") If $Search = -1 Then MsgBox(0, "Error", "No files/directories found.") EndIf While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop If $filecounter >= 20 Then GUICtrlSetData($indexstatuslabel, $file) $filecounter = $filecounter + 1 EndIf ;ignore the stupid generic system files that we don't care about If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else #comments-start ;i think this is causing lapses on large files, if the file is large, then it takes a while to get the attributes and is reving the drives ;checks to see if there is a D anywhere in the FileGetAttrib string because if there is, that means it is a directory If StringInStr(FileGetAttrib($drive & "\" & $file),"D") > 0 Then #comments-end $test = FileOpen($drive & "\" & $file, 0) If $test = -1 Then ;calls the second half of the indexing engine designed specifically for dealing with subfolders Call(indexingengine2($drive & "\" & $file)) Else ;msgbox(0,"","") FileClose($test) $indexoutput &= $drive & "\" & $file & @LF $filecounter = $filecounter + 1 ;~ IniWrite($filetosave,$file,$drive & "\",Round(Filegetsize($drive & "\" & $file),0)) ;FileWriteLine($filetosavehandle, $drive & "\" & $file) ;~ IniWrite($filepath,$file,"","") EndIf EndIf If $usercancel = "true" Then ExitLoop WEnd If $usercancel = "true" Then ExitLoop GUICtrlSetData($indexstatuslabel, "Sorting Index...") $indexinput = StringSplit(StringTrimRight($indexinput, 1), @LF) _ArraySort($indexinput, False, 1) GUICtrlSetData($indexstatuslabel, "Compiling Index...") For $Z = 1 To $indexinput[0] Local $Record = StringSplit($indexinput[$Z], @TAB) If IsArray($Record) Then If $Record[1] <> $CurrentFile Then $fileoutput &= '[' & $Record[1] & ']' & @LF $titleindex &= $Record[1] & @LF $CurrentFile = $Record[1] EndIf If $Record[0] >= 3 Then $fileoutput &= $Record[2] & '=' & $Record[3] & @LF EndIf If $usercancel = "true" Then ExitLoop Next GUICtrlSetData($indexstatuslabel, "Writing Index to File...") If Not FileExists(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".index") Then _FileCreate(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".index") EndIf $filetosavehandle = FileOpen($filepath, 1) $masterindex = FileOpen(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".index", 2) FileWriteLine($masterindex, $titleindex) FileWriteLine($filepath, $fileoutput) FileClose($masterindex) FileClose($filetosavehandle) ;close file to save to handle ;close the search handle FileClose($Search) $titleindex = "" $fileoutput = "" $CurrentFile = "" $numberofelements = $indexinput[0] ;~ Redim $indexinput[1] $indexinput = "" ;~ ReDim $Record[1] $Record = "" ;~ For $placeholder = 0 To $numberofelements ;~ $indexinput[$placeholder] = "" ;~ Next ;msgbox(0,"value of I",$i) Next EndIf If $usercancel = "true" Then FileClose($filetosavehandle) FileClose($Search) EndIf #cs this statement runs if the user hasn't selected all drives to index on the main GUI (i know, not efficient as calling them as fuctions with a variable but i got lazy for example, i could have done this call(indexingengine("all drives")) or call(indexingengine("c")) but didn't feel like modifying the engine code ;) #ce Else ;i did this because i had stored the same data earlier in this script as $drive, so i just made $drive equal to it $drive = $readdrivecomboindex ;sets the location and filename of the index file $filepath = @ScriptDir & "\title" & StringTrimRight($drive, 1) & ".index" ;creates the file that the index data will be saved to in case the file doesn't already exist If Not FileExists($filepath) Then _FileCreate($filepath) Else FileMove($filepath, $filepath & ".bak", 1) _FileCreate($filepath) EndIf $filetosavehandle = FileOpen($filepath, 1) $Search = FileFindFirstFile($drive & "\*.*") If $Search = -1 Then MsgBox(0, "Error", "No files/directories found.") EndIf While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop If $filecounter >= 20 Then GUICtrlSetData($indexstatuslabel, $file) $filecounter = $filecounter + 1 EndIf $filecounter = $filecounter ;this are some stupid generic system files that are found all over the place, i just tell the index engine to ignore them because they really aren't important If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else #comments-start ;i think this is causing lapses on large files, if the file is large, then it takes a while to get the attributes and is reving the drives ;checks to see if there is a D anywhere in the FileGetAttrib string because if there is, that means it is a directory If StringInStr(FileGetAttrib($drive & "\" & $file),"D") > 0 Then #comments-end ;open the file that is currently being searched to check to see if it is a file or a folder(if it is a folder, the fileopen fails) $test = FileOpen($drive & "\" & $file, 0) ;tests to see what happened with the fileopen If $test = -1 Then ;calls the second half of the indexing engine designed specifically for dealing with subfolders Call(indexingengine2($drive & "\" & $file)) Else ;the file is a file and not a directory, k now that we know this, close the file FileClose($test) AddEntry($drive & "\" & $file, $indexinput) ;~ previously used, but it is very slow when the index files become very large(is faster when searching though) ;~ IniWrite($filetosave,$file,$drive & "\",Round(Filegetsize($drive & "\" & $file),0)) ;write the file's full path to the index file ;FileWriteLine($filetosavehandle, $drive & "\" & $file) ;~ in an attempt to speed up the search process, i had it write the filenames only to another title index file which the search engine would search ;~ IniWrite($filepath,$file,"","") EndIf EndIf ;this little line allows the user to cancel out of the indexing process by pressing the esc key(see the cancel function) If $usercancel = "true" Then ExitLoop WEnd ;writes the output to the file GUICtrlSetData($indexstatuslabel, "Sorting Index...") $indexinput = StringSplit(StringTrimRight($indexinput, 1), @LF) _ArraySort($indexinput, False, 1) GUICtrlSetData($indexstatuslabel, "Compiling Index...") For $i = 1 To $indexinput[0] Local $Record = StringSplit($indexinput[$i], @TAB) If $Record[1] <> $CurrentFile Then $fileoutput &= '[' & $Record[1] & ']' & @LF $titleindex &= $Record[1] & @LF $CurrentFile = $Record[1] EndIf $fileoutput &= $Record[2] & '=' & $Record[3] & @LF If $usercancel = "true" Then ExitLoop Next GUICtrlSetData($indexstatuslabel, "Writing Index to File...") If Not FileExists(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index") Then _FileCreate(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index") EndIf $masterindex = FileOpen(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index", 2) FileWrite($masterindex, $titleindex) FileWrite($filepath, $fileoutput) ;close file to save to handle FileClose($masterindex) FileClose($filetosavehandle) ;close the search handle FileClose($Search) ;~ ReDim $Record[1] ;~ $Record[0] = "" $Record = 0 $indexinput = 0 ;~ For $i = 1 To $indexinput[0] ;~ $indexinput[$i] = "" ;~ Next EndIf If @Compiled = 1 Then ProcessSetPriority(@ScriptName, 2) EndIf ;hides the indexing GUI dialogue because the index is now complete GUISetState(@SW_HIDE, $indexingGUI) ;show the main GUI window (the first dialogue) GUISetState(@SW_SHOW, $mainGUI) HotKeySet("{Esc}") ;determines if the script ended pretmaturely If $usercancel = "true" Then ;overwrites the unfinished newer index file with the older complete index file FileMove($filepath & ".bak", $filepath, 1) ;notifies the user that the script was cancelled MsgBox(0, "Canceled", "The indexing has been canceled.") Else ;if the script hasn't ended prematurely, then it has made a new index of the drive and can now delete the older out-of-date index backup file $fixeddrives = DriveGetDrive( "FIXED") For $i = 1 To $fixeddrives[0] $filepath = @ScriptDir & "\title" & StringTrimRight($fixeddrives[$i], 1) & ".index" If FileExists($filepath & ".bak") Then FileDelete($filepath & ".bak") Next MsgBox(0, "Done", "Done Creating the Index.") EndIf EndFunc ;==>IndexingEngine Func DBEngine() If @Compiled = 1 Then ProcessSetPriority(@ScriptName, 0) EndIf ;makes sure the starting value of the usercancel is set to false, otherwise the indexing engine will shut down before it starts $usercancel = "false" ;sets the output equal to nothing $indexoutput = "" ;set the cancel escape key as escape HotKeySet("{Esc}", "Cancel") ;hide the main GUI since we don't care about it anymore GUISetState(@SW_HIDE, $mainGUI) ;create the indexing GUI that will display data on the current file being indexed $indexingGUI = GUICreate("Indexing... (Esc cancels)", 500, 50, (@DesktopWidth - 500) / 2, (@DesktopHeight - 50) / 2) ;creates a label for the indexing GUI GUICtrlCreateLabel("Indexing. This may take a while. Please Wait...", 30, 1, 250, 25) ;creates another label where the filenames will be stored as it processes the files $indexstatuslabel = GUICtrlCreateLabel("", 20, 25, 280, 20) ;creates the GUI GUISetState() $filecounter = 0 ;reads the combobox to check what drives the user wants indexed $readdrivecomboindex = GUICtrlRead($drivecomboindex) ;check the else on this if statement to get the more commmented version of my engine If $readdrivecomboindex = "All Drives" Then $fixeddrives = DriveGetDrive("FIXED") If Not @error Then ;will loop the engine for every fixed drive on the computer For $i = 1 To $fixeddrives[0] ;~ msgbox("0","All Drives For Loop","The main all drives for loop has been activated. Number of drives is " & $fixeddrives[0] & ". The current drive is drive " & $fixeddrives[$i] & ".",20) $drive = $fixeddrives[$i] $DBpath = @ScriptDir & "\title" & StringTrimRight($drive, 1) & ".db" If Not FileExists($DBpath) Then ;_FileCreate($DBpath) Else FileMove($DBpath, $DBpath &"_DB_"& ".bak", 1) ;_FileCreate($DBpath) EndIf $Search = FileFindFirstFile($drive & "\*.*") If $Search = -1 Then MsgBox(0, "Error", "No files/directories found.") EndIf While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop If $filecounter >= 20 Then GUICtrlSetData($indexstatuslabel, $file) $filecounter = $filecounter + 1 EndIf ;ignore the stupid generic system files that we don't care about If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else #comments-start ;i think this is causing lapses on large files, if the file is large, then it takes a while to get the attributes and is reving the drives ;checks to see if there is a D anywhere in the FileGetAttrib string because if there is, that means it is a directory If StringInStr(FileGetAttrib($drive & "\" & $file),"D") > 0 Then #comments-end $test = FileOpen($drive & "\" & $file, 0) If $test = -1 Then ;calls the second half of the indexing engine designed specifically for dealing with subfolders Call(indexingengine2($drive & "\" & $file)) Else FileClose($test) $indexoutput &= $drive & "\" & $file & @LF $filecounter = $filecounter + 1 EndIf EndIf If $usercancel = "true" Then ExitLoop WEnd If $usercancel = "true" Then ExitLoop ;GUICtrlSetData($indexstatuslabel, "Sorting Index...") ;$indexinput = StringSplit(StringTrimRight($indexinput, 1), @LF) ;_ArraySort($indexinput, False, 1) ;GUICtrlSetData($indexstatuslabel, "Compiling Index...") ;For $Z = 1 To $indexinput[0] ; Local $Record = StringSplit($indexinput[$Z], @TAB) ; If IsArray($Record) Then ; If $Record[1] <> $CurrentFile Then ; $fileoutput &= '[' & $Record[1] & ']' & @LF ; $titleindex &= $Record[1] & @LF ; $CurrentFile = $Record[1] ; EndIf ; If $Record[0] >= 3 Then $fileoutput &= $Record[2] & '=' & $Record[3] & @LF ; EndIf If $usercancel = "true" Then ExitLoop Next GUICtrlSetData($indexstatuslabel, "Writing Index to File...") ;If Not FileExists(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".db") Then ; _FileCreate(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".db") ;EndIf $filetosavehandle = FileOpen($DBpath, 1) $masterindex = FileOpen(@ScriptDir & "\masterindex" & StringTrimRight($drive, 1) & ".db", 2) FileWriteLine($masterindex, $titleindex) FileWriteLine($DBpath, $fileoutput) FileClose($masterindex) FileClose($filetosavehandle) ;close file to save to handle ;close the search handle FileClose($Search) $titleindex = "" $fileoutput = "" $CurrentFile = "" $numberofelements = $indexinput[0] ;~ Redim $indexinput[1] $indexinput = "" ;~ ReDim $Record[1] $Record = "" ;~ For $placeholder = 0 To $numberofelements ;~ $indexinput[$placeholder] = "" ;~ Next ;msgbox(0,"value of I",$i) Next EndIf If $usercancel = "true" Then FileClose($filetosavehandle) FileClose($Search) EndIf Else ;i did this because i had stored the same data earlier in this script as $drive, so i just made $drive equal to it $drive = $readdrivecomboindex ;sets the location and filename of the index file $DBpath = @ScriptDir & "\title" & StringTrimRight($drive, 1) & ".db" ;creates the file that the index data will be saved to in case the file doesn't already exist If Not FileExists($DBpath) Then ;_FileCreate($DBpath) Else FileMove($DBpath, $DBpath & "_DB_"&".bak", 1) ;_FileCreate($DBpath) EndIf $filetosavehandle = FileOpen($DBpath, 1) $Search = FileFindFirstFile($drive & "\*.*") If $Search = -1 Then MsgBox(0, "Error", "No files/directories found.") EndIf While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop If $filecounter >= 20 Then GUICtrlSetData($indexstatuslabel, $file) $filecounter = $filecounter + 1 EndIf $filecounter = $filecounter ;this are some stupid generic system files that are found all over the place, i just tell the index engine to ignore them because they really aren't important If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else #comments-start ;i think this is causing lapses on large files, if the file is large, then it takes a while to get the attributes and is reving the drives ;checks to see if there is a D anywhere in the FileGetAttrib string because if there is, that means it is a directory If StringInStr(FileGetAttrib($drive & "\" & $file),"D") > 0 Then #comments-end ;open the file that is currently being searched to check to see if it is a file or a folder(if it is a folder, the fileopen fails) $test = FileOpen($drive & "\" & $file, 0) ;tests to see what happened with the fileopen If $test = -1 Then ;calls the second half of the indexing engine designed specifically for dealing with subfolders Call(indexingengine2($drive & "\" & $file)) Else ;the file is a file and not a directory, k now that we know this, close the file FileClose($test) AddEntry($drive & "\" & $file, $indexinput) ;~ previously used, but it is very slow when the index files become very large(is faster when searching though) ;~ IniWrite($filetosave,$file,$drive & "\",Round(Filegetsize($drive & "\" & $file),0)) ;write the file's full path to the index file ;FileWriteLine($filetosavehandle, $drive & "\" & $file) ;~ in an attempt to speed up the search process, i had it write the filenames only to another title index file which the search engine would search ;~ IniWrite($filepath,$file,"","") EndIf EndIf ;this little line allows the user to cancel out of the indexing process by pressing the esc key(see the cancel function) If $usercancel = "true" Then ExitLoop WEnd ;writes the output to the file GUICtrlSetData($indexstatuslabel, "Sorting Index...") $indexinput = StringSplit(StringTrimRight($indexinput, 1), @LF) _ArraySort($indexinput, False, 1) GUICtrlSetData($indexstatuslabel, "Compiling Index...") For $i = 1 To $indexinput[0] Local $Record = StringSplit($indexinput[$i], @TAB) If $Record[1] <> $CurrentFile Then $fileoutput &= '[' & $Record[1] & ']' & @LF $titleindex &= $Record[1] & @LF $CurrentFile = $Record[1] EndIf $fileoutput &= $Record[2] & '=' & $Record[3] & @LF If $usercancel = "true" Then ExitLoop Next GUICtrlSetData($indexstatuslabel, "Writing Index to File...") If Not FileExists(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index") Then _FileCreate(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index") EndIf $masterindex = FileOpen(@ScriptDir & "\masterindex" & StringTrimRight($readdrivecomboindex, 1) & ".index", 2) FileWrite($masterindex, $titleindex) FileWrite($DBpath, $fileoutput) ;close file to save to handle FileClose($masterindex) FileClose($filetosavehandle) ;close the search handle FileClose($Search) ;~ ReDim $Record[1] ;~ $Record[0] = "" $Record = 0 $indexinput = 0 ;~ For $i = 1 To $indexinput[0] ;~ $indexinput[$i] = "" ;~ Next EndIf If @Compiled = 1 Then ProcessSetPriority(@ScriptName, 2) EndIf ;hides the indexing GUI dialogue because the index is now complete GUISetState(@SW_HIDE, $indexingGUI) ;show the main GUI window (the first dialogue) GUISetState(@SW_SHOW, $mainGUI) HotKeySet("{Esc}") ;determines if the script ended pretmaturely If $usercancel = "true" Then ;overwrites the unfinished newer index file with the older complete index file FileMove($DBpath &"_DB_"& ".bak", $DBpath, 1) ;notifies the user that the script was cancelled MsgBox(0, "Canceled", "The indexing has been canceled.") Else ;if the script hasn't ended prematurely, then it has made a new index of the drive and can now delete the older out-of-date index backup file $fixeddrives = DriveGetDrive( "FIXED") For $i = 1 To $fixeddrives[0] $DBpath = @ScriptDir & "\title" & StringTrimRight($fixeddrives[$i], 1) & ".index" If FileExists($DBpath &"_DB_"& ".bak") Then FileDelete($DBpath &"_DB_"& ".bak") Next MsgBox(0, "Done", "Done Creating the Index.") EndIf EndFunc ;==>DBEngine ;the second instance of the indexing engine. This is called and used to search subfolders Func indexingengine2($x) $Search = FileFindFirstFile($x & "\*.*") While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop GUICtrlSetData($indexstatuslabel, $file) If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else $test = FileOpen($x & "\" & $file, 0) If $test = -1 Then ;calls another instance of this function so that it can search for futher subfolders withing subfolders Call(indexingengine2($x & "\" & $file)) Else FileClose($test) AddEntry($x & "\" & $file, $indexinput) EndIf EndIf WEnd FileClose($Search) EndFunc ;==>indexingengine2 Func DBengine2($x) $Search = FileFindFirstFile($x & "\*.*") While 1 $file = FileFindNextFile($Search) If @error Then ExitLoop If $usercancel = "true" Then ExitLoop GUICtrlSetData($indexstatuslabel, $file) If $file = "Thumbs.db" Or $file = "desktop.ini" Or $file = "Folder.jpg" Or $file = "AlbumArtSmall.jpg" Or $file = "AlbumArtLarge.jpg" Then Else $test = FileOpen($x & "\" & $file, 0) If $test = -1 Then ;calls another instance of this function so that it can search for futher subfolders withing subfolders Call(DBengine2($x & "\" & $file)) Else FileClose($test) AddEntryDB($x & "\" & $file, $indexinput) EndIf EndIf WEnd FileClose($Search) EndFunc ;==>indexingengine2 ;LxP wrote this Func AddEntryDB($Path, ByRef $indexinput) ; Split path into folder and file Local $LastSlashLoc = StringInStr($Path, '\', False, -1) If $LastSlashLoc = 0 Then SetError(1) Return False EndIf Local $Folder = StringLeft($Path, $LastSlashLoc) Local $file = StringTrimLeft($Path, $LastSlashLoc) ; Get size of file Local $Size = FileGetSize($Path) If @error Then SetError(2) Return False EndIf $indexinput &= $file & @TAB & $Folder & @TAB & $Size & @LF EndFunc ;==>AddEntry Func AddEntry($Path, ByRef $indexinput) ; Split path into folder and file Local $LastSlashLoc = StringInStr($Path, '\', False, -1) If $LastSlashLoc = 0 Then SetError(1) Return False EndIf Local $Folder = StringLeft($Path, $LastSlashLoc) Local $file = StringTrimLeft($Path, $LastSlashLoc) ; Get size of file Local $Size = FileGetSize($Path) If @error Then SetError(2) Return False EndIf $indexinput &= $file & @TAB & $Folder & @TAB & $Size & @LF EndFunc ;==>AddEntry ;used in the event that a user presses Escape while the search engine is running or while the indexing engine is running. Func Cancel() ;checks to make sure the user is pressing cancel for the search engine and not for some other program that have open while the search engine is running If WinActive("Searching... (Esc cancels)") Then $answer = MsgBox(292, "Cancel?", "Are you sure you want to cancel the search?") If $answer = 6 Then $usercancel = "true" HotKeySet("{Esc}") EndIf ;checks to make sure the user is pressing cancel for the indexing engine and not for some other program that have open while the indexing engine is running ElseIf WinActive("Indexing... (Esc cancels)") Then $answer = MsgBox(292, "Cancel?", "Are you sure you want to cancel the index? All index progress will be lost.") If $answer = 6 Then $usercancel = "true" HotKeySet("{Esc}") EndIf Else HotKeySet("{Esc}") Send("{Esc}") HotKeySet("{Esc}", "Cancel") EndIf EndFunc ;==>Cancel ;i wrote this in case the program encounters an error. I was hoping this error message would be friendly than the "AUTO IT ERROR LINE 165 "fileClose()" blah blah" Func Error() MsgBox(4112, "Error!", "An error has occured and the Search/Indexing Engine must close.") Exit EndFunc ;==>Error