Reputation: 3215
At work, Windows file indexing is disabled. As a workaround, I created 3 scripts using Autohotkey v1.1.22.00 to (1) allow launching of a search user interface when I press the Control key twice quickly, (2) index files in the locations I select, (3) quickly search for files using keywords, and (4) use the search interface to launch a Google web search. I posted my scripts as an answer below.
I'm curious to know if this works for anyone else, or if someone else can improve this or provide a better solution.
Thanks!
Upvotes: 1
Views: 2798
Reputation: 3215
This last script contains the web search functionality and just launches a browser into a Google search.
Sleep, 250
if (WebSearchTerm)
SearchPar := WebSearchTerm
Else
Inputbox, SearchPar, Quick Google Search, Examples:`nMap San Francisco`, CA to Sacramento`, CA`n- DLC 729 [SEARCH DESKTOP] , , , 175, , , , , %WebSearchTerm%
If ErrorLevel
Sleep, 25
Else
{
If (SearchPar <> "")
{
SpecialSearch :=
If (SearchPar = " ")
{
Run, _SEARCH\SearchFiles\SearchFiles.ahk
}
Else
{
StringLeft, CheckMap, SearchPar, 3
IfNotInString, SearchPar, to
CheckMap :=
If (CheckMap = "map")
{
; Fix searches using the '&' symbol
ReplaceAND := " & "
StringReplace, SearchPar, SearchPar, %ReplaceAND%, &, All
StringReplace, SearchPar, SearchPar, &, +`%26+, All
; *********************************
SpecialSearch = 1
StringTrimLeft, SearchPar, SearchPar, 4
StringReplace, SearchPar, SearchPar, %A_SPACE%to%A_SPACE%, -, All
StringSplit, MapLocations, SearchPar, -
StringReplace, MapLocations1, MapLocations1, %A_Space%, +, All
StringReplace, MapLocations2, MapLocations2, %A_Space%, +, All
Run, http://maps.google.com/maps?saddr=%MapLocations1%&daddr=%MapLocations2%
}
StringLeft, CheckDesktopSearch, SearchPar, 2
If (CheckDesktopSearch = "- ")
{
SpecialSearch = 1
StringTrimLeft, SearchPar, SearchPar, 2
Send, {LWIN}
Sleep, 250
Send, %SearchPar%
}
If (SpecialSearch = "")
{
; Fix searches using the '&' symbol
ReplaceAND := " & "
StringReplace, SearchPar, SearchPar, %ReplaceAND%, &, All
StringReplace, SearchPar, SearchPar, &, +`%26+, All
Run, http://www.google.com/search?q=%SearchPar%&sourceid=ie7&rls=com.microsoft:en-us:IE-Address&ie=&oe=&safe=active
}
}
}
}
Upvotes: 1
Reputation: 3215
Here are the three scripts I use together to index and quickly search about 150,000 networked files. I scheduled the index to run early every morning. It creates a CSV file that stores file names, locations, size and date/time they were last modified to show recently modified files at the top of the results.
The index is presorted by date/time modified with recently modified files first. This allows the script to quickly return results with the more recently modified files which I use more often, while complete results usually take 6 - 10 seconds.
(1) allow launching of a search user interface when I press the Control key twice quickly, (2) index files in the locations I select, (3) quickly search for files using keywords, and (4) use the search interface to launch a Google web search.
Here's a script to setup a double tap of CTRL as a hotkey to launch the search UI. Change the value of the var "SearchAppPath" to match the location of the AHK file with the search UI.
; LAUNCH SEARCH UI BY PRESSING CONTROL TWICE
CTRL::
If (A_PriorHotKey = "Ctrl" AND A_TimeSincePriorHotkey < 500)
{
IfWinNotExist FILE SEARCH ahk_class AutoHotkeyGUI
IfWinNotExist SearchFiles ahk_class AutoHotkeyGUI
{
SearchAppPath := "SearchFiles_v3.4.ahk"
Run, %SearchAppPath%
}
else
WinActivate SearchFiles ahk_class AutoHotkeyGUI
Else
Winactivate FILE SEARCH ahk_class AutoHotkeyGUI
}
else
SetTimer, NumpadEndDefault, -500
Return
NumpadEndDefault:
Send, {Ctrl}
Return
The next script indexes files. It can be run manually or from within the search UI.
; SET SEARCH LOCATIONS (sub-folders included by default)
Location1 := "C:\Finance Group Data" ; FINANCE GROUP DATA
Location2 := "\\fileprint\users$\" . A_UserName ; CURRENT USER FOLDERS (MY DOCUMENTS, DESKTOP, ETC.)
; add additional locations (e.g. Location3, Location4, etc.)
; SPECIFIC PROGRAMS/FILES TO INCLUDE AS FIRST RESULTS IF MATCHED
CurrentDateTime := A_YYYY . A_MM . A_DD . A_Hour . A_Min . A_Sec ; current timestamp, to show these files as the most current, and therefore at the top of search results
FileList .= CurrentDateTime . ",calc.exe,C:\Windows\system32\calc.exe,15`n"
FileList .= CurrentDateTime . ",notepad.exe,C:\Windows\system32\notepad.exe,15`n"
FileList .= CurrentDateTime . ",cmd.exe,C:\Windows\system32\cmd.exe,15`n"
FileList .= CurrentDateTime . ",Microsoft Outlook 2010,C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk,1`n"
FileList .= CurrentDateTime . ",mspaint.exe,C:\Windows\system32\mspaint.exe,15`n"
; INDEX FILE LOCATION IS IN THE CURRENT USER'S MY DOCUMENTS FOLDER
INDEX_FILE := A_MyDocuments . "\FileIndex.csv"
INDEX_FILE2 := A_MyDocuments . "\FileIndexFULL.csv"
; INCREASE MAXIMUM MEMORY ALLOWED FOR EACH VARIABLE - NECESSARY FOR THE INDEXING VARIABLE
#MaxMem 4095
; COUNT THE NUMBER OF SEARCH LOCATIONS
n :=
Loop
{
n++
Location := Location%n%
If (Location%n% = "")
{
n--
Break
}
}
; CREATE GUI
Gui, Add, Text, w1250, Indexing Files...
Gui, Add, StatusBar, +wrap, Bar's starting text
SB_SetParts(65)
SB_SetText(A_LoopFileFullPath)
Gui, Show
; INDEX FILES AND UPDATE GUI WITH STATUS
Loop, %n%
{
ThisFolder := Location%A_Index%
Loop, %ThisFolder%\*.*, 0, 1
{
; EXCLUDE FILES FROM THE SEARCH DATABASE (modify as necessary)
if A_LoopFileName not contains $,~,.tmp,.ddf,.bak,.gg,.ini,.DS_Store,.db,.url,.ahk.bak,.upd,.ctx,.dll,.indd,.SESSION,.PROPERTIES,.TEXTCLIPPING,.eps,.idml,.zbin,.swf,.strings,.rsrc,.psb,.lst,.lrtemplate,framework,.aapp,.aaui,.ai,.asfx,.bin,.eve,.exv,.nav,.nib,.pak,.plist,.sequ,.abr,.1,.acb,.acv,.afm,.ase,.atn,.cer,.cnv,.CR2,.crv,.csh,.css,.dat,.der,.dic,.emf,.eml,.fla,.flt,.FON,.h,.hqx,.htm,.icc,.inx,.ipp,.js,.kfp,.kfr,.ln,.lnk,.log,.lwo,.mac,.MMM,.NEF,.PFB,.PFM,.ps,.rc,.so,.spp,.svg,.ttc,.vc,.vcf,.wmf,.xdc,.ico,.ilex,.api,.bat,.BML,.BMS,.BUP,.cab,.CAC,.CD,.cfg,.conf,.cptx,.DFN,.dif,.dir,.glox,.icns,.ID,.idms,.IFO,.indb,.indl,.indt,.inf,.io,.lua,.ocr,.ocx,.otf,.p12,.pat,.pct,.pds,.pem,.pfx,.php,.rrt,.rwz,.scpt,.sdef,.sitx,.thmx,.ttf,.VOB,.vsd,.vss,.xmp,.xnk,.xsd,.xsl,.img,.xml,.psb,.psd,.eps
{
; Skip any file that is either H (Hidden), R (Read-only), or S (System). Note: No spaces in "H,R,S".
if A_LoopFileAttrib contains H,R,S
continue
; Skip any file without a file extension
If (A_LoopFileExt = "")
continue
; If the file name contains a comma, put quotation marks around the field to prepare it for insertion into a CSV file
ModA_LoopFileName := A_LoopFileName
IfInString, A_LoopFileName, `,
ModA_LoopFileName := """" . A_LoopFileName . """"
; If the file path contains a comma, put quotation marks around the field to prepare it for insertion into a CSV file
ModA_LoopFileFullPath := A_LoopFileFullPath
IfInString, A_LoopFileFullPath, `,
ModA_LoopFileFullPath := """" . A_LoopFileFullPath . """"
; Save details of file
FileList .= A_LoopFileTimeModified . "," . ModA_LoopFileName . "," . ModA_LoopFileFullPath . "," . A_LoopFileSizeKB . "`n"
FileList2 .= A_LoopFileTimeModified . "," . ModA_LoopFileName . "," . ModA_LoopFileFullPath . "," . A_LoopFileSizeKB . "`n"
; GUI Status Update
FileCount++
If ((FileCount / 13) = ROUND(FileCount / 13, 0))
{
SB_SetText(FileCount . " files", 1)
SB_SetText(A_LoopFileFullPath, 2)
Gui, Show, NA
}
}
; EXCLUDED FILES: Save to a second file as a backup source
else
{
; If the file NAME contains a comma, put quotation marks around the field to prepare it for insertion into a CSV file
ModA_LoopFileName := A_LoopFileName
IfInString, A_LoopFileName, `,
ModA_LoopFileName := """" . A_LoopFileName . """"
; If the file PATH contains a comma, put quotation marks around the field to prepare it for insertion into a CSV file
ModA_LoopFileFullPath := A_LoopFileFullPath
IfInString, A_LoopFileFullPath, `,
ModA_LoopFileFullPath := """" . A_LoopFileFullPath . """"
; Save details of file
FileList2 .= A_LoopFileTimeModified . "," . ModA_LoopFileName . "," . ModA_LoopFileFullPath . "," . A_LoopFileSizeKB . "`n"
}
}
}
; GUI Status Update
SB_SetText("SORTING RESULTS...", 1)
SB_SetText("", 2)
Gui, Show, NA
; SORT the file list from newest to oldest based on the modified date, which is now the first CSV column
; Sort, FileList , N R
Sort, FileList , R
; GUI Status Update
SB_SetText("RE-SORTING RESULTS...", 1)
SB_SetText("", 2)
Gui, Show, NA
; GUI Status Update
SB_SetText("DELETING INDEX FILE", 1)
SB_SetText("", 2)
Gui, Show, NA
; DELETE INDEX FILE IF IT ALREADY EXISTS
IfExist, %INDEX_FILE%
FileDelete, %INDEX_FILE%
IfExist, %INDEX_FILE2%
FileDelete, %INDEX_FILE2%
Sleep, 2500
; GUI Status Update
SB_SetText("CREATING PRIMARY INDEX FILE", 1)
SB_SetText("", 2)
Gui, Show, NA
; CREATE PRIMARY INDEX FILE
FileAppend, %FileList%, %INDEX_FILE%
; GUI Status Update
SB_SetText("CREATING SECONDARY INDEX FILE (NO EXCLUDED FILES)", 1)
SB_SetText("", 2)
Gui, Show, NA
; CREATE SECONDARY INDEX FILE
FileAppend, %FileList2%, %INDEX_FILE2%
; GUI Status Update
SB_SetText("COMPLETE", 1)
SB_SetText("", 2)
Gui, Show, NA
; END RE-INDEX
GUI Destroy
ExitApp
The final script contains the actual search user interface.
; INDEX FILE LOCATION IS IN THE USERS MY DOCUMENTS FOLDER
INDEX_FILE := A_MyDocuments . "\FileIndex.csv"
; ***** FUNCTION, SECONDS TIMER ***
; Calculates the time in seconds from a starting time to ending time.
; Use the StartTimer() to store a starting time.
; Use the EndTimer() function to calculate the seconds between the current time and start time
StartTimer()
{
return (A_DD * 24 * 60 * 60) + (A_Hour * 60 * 60) + (A_Min * 60) + A_Sec + ((A_MSec + 0) / 1000)
}
EndTimer(StartTime)
{
return (A_DD * 24 * 60 * 60) + (A_Hour * 60 * 60) + (A_Min * 60) + A_Sec + ((A_MSec + 0) / 1000) - StartTime
}
; EXAMPLE:
; MyStartTime := StartTimer()
; Msgbox % "Starting time logged."
; MyElapsedTime := EndTimer(MyStartTime)
; Msgbox % "Starting Time: " . MyStartTime . " seconds`nEnding Time: " . MyStartTime + MyElapsedTime . " seconds`nElapsed Time: " . MyElapsedTime . " seconds"
; ***** FUNCTION DateInDays ***
; ------- Requires the custom function 'IsLeapDay' -------
; Returns a date & timestamp as an integer representing a
; number of days that can easily be compared to another.
DateInDays(timestamp)
{
If (timestamp = 0)
timestamp := FormatTime, timestamp
FormatTime, TM_Year, %timestamp%, yyyy
FormatTime, TM_Month, %timestamp%, M
FormatTime, TM_Day, %timestamp%, d
; Determine if leap year
LeapDay = 0
if(TM_Month > 2)
LeapDay := IsLeapDay(TM_Year)
; Number of days in the year up to the end of the prior month
MonthDays1 := 0
MonthDays2 := 31
MonthDays3 := 59
MonthDays4 := 90
MonthDays5 := 120
MonthDays6 := 151
MonthDays7 := 181
MonthDays8 := 212
MonthDays9 := 243
MonthDays10 := 273
MonthDays11 := 304
MonthDays12 := 334
MonthDays := MonthDays%TM_Month%
Return (TM_Year * 365) + (MonthDays%TM_Month%) + TM_Day + LeapDay ; return total days
}
; Get the last search term if it was searched recently
LAST_SEARCH_FILE := A_MyDocuments . "\LastSearch.tmp"
IfExist, %LAST_SEARCH_FILE%
{
FileGetTime, LastSearchTime, %LAST_SEARCH_FILE% ; get the timestamp of the last search
CurrentDateTime := A_YYYY . A_MM . A_DD . A_Hour . A_Min . A_Sec ; current timestamp
LastSearchAge := CurrentDateTime - LastSearchTime ; get the age of the last search in seconds
If (LastSearchAge < 300 AND LastSearchAge > 0) ; if the last search was made less than 5 minutes (300 seconds) ago...
FileRead, LastSearchTerm, %LAST_SEARCH_FILE% ; get the last search term to use as the default new search
}
; USE UN-EXACT WINDOW NAME MATCH BY DEFAULT
SetTitleMatchMode, 2
SendMode, Input
; SET WORKING DIRECTORY
; **** FUNCTION: WAIT FOR AND ACTIVATE WINDOW
; **** EXAMPLE ****
; WaitAll("Peachtree", "Customers")
WaitAll(x, y = 0)
; x = Window Name
; y = Window Text (optional)
{
if y = 0
y :=
WinWait, %x%, %y%
IfWinNotActive, %x%, %y%
WinActivate, %x%, %y%
WinWaitActive, %x%, %y%
; return x + y ; "Return" expects an expression.
}
; END FUNCTION ***
; CLEAR VARIABLE WHEN SEARCH IS RUN
; LastSearchTerm :=
; FUNCTION TO FORMAT NUMBERS with commas (ex. 43485394 = 43,485,394)
ThousandsSep(x, s=",")
{
return RegExReplace(x, "\G\d+?(?=(\d{3})+(?:\D|$))", "$0" s)
}
; ***** FUNCTION IsLeapDay ****************************
IsLeapDay(year)
{
; Returns a 1 if the year is a leap year.
; Otherwise returns a 0.
; Year is a 4 digit number or a variable resolving to a 4 digit number.
if((year / 4) != ROUND(year / 4, 0))
Return 0
Else
if((year / 100) != ROUND(year / 100, 0))
Return 1
Else
if((year / 400) != ROUND(year / 400, 0))
Return 0
Else
Return 1
}
StartThisMacro:
; Limit the number of search results
ResultsLimit := 100000
; Identify the current GUI window
CurrentGUI := "Parameters"
; CLEAR VARIABLES EACH TIME SEARCH PARAMETERS ARE UPDATED
SearchTerm :=
ThisMessage :=
Loop, 99
SearchTerms%A_INDEX% :=
SearchTermCount :=
Loop, 99
QuotePos%A_INDEX% :=
nn :=
Loop, 99
Quote%A_INDEX% :=
Loop, 99
SearchTermQuoteArray%A_INDEX% :=
RefPos :=
NumQuotes :=
QuoteA :=
QuoteB :=
Modifier :=
QuoteLen :=
QuotePos :=
LastQuotePos :=
SearchTermTemp :=
ThisQuote :=
LineNumber :=
NotFoundA :=
ThisFileLocationNew :=
ThisSearch :=
ThisSearchCheck :=
NumberOfResults :=
FoundMatch :=
MatchedFileName :=
MatchedFilePath :=
MatchedFileDir :=
MatchedFileExtension :=
MatchedFileNameNoExt :=
MatchedFileDrive :=
NumberOfResultsFormatted :=
BreakOutExclude :=
SearchTerm2 :=
ThisSearchTerm2 :=
NewSearchTerm :=
FilterText :=
SearchTermLen :=
FoundPos :=
FoundPos2 :=
FoundPos3 :=
SubPat :=
SubPatLen :=
DateModifiedFilterDays :=
SearchTermL :=
SearchTermR :=
; CLEAN UP LAST SEARCH PARAMETERS
StringRight, LastSearchTermLastChar, LastSearchTerm, 1
If (LastSearchTermLastChar = " ")
StringTrimRight, LastSearchTerm, LastSearchTerm, 1
; NEW SEARCH SECTION
; Identify the current GUI window
CurrentGUI := "Parameters"
; SEARCH BOX
Gui, font, s11, Verdana ; Set font
Gui, Add, Edit, vSearchTerm w400, %LastSearchTerm%
; SEARCH FILES BUTTON
Gui, font, s14, Verdana ; Set font
Gui, Add, Button, gSearchFiles default, SEARCH DESKTOP ; The label StartSearch (if it exists) will be run when the button is pressed.
; SEARCH INTERNET BUTTON
Gui, font, s14, Verdana ; Set font
Gui, Add, Button, gSearchInternet, SEARCH INTERNET ; The label StartSearch (if it exists) will be run when the button is pressed.
; SHOW RECENT ITEMS BUTTON
Gui, font, s14, Verdana ; Set font
Gui, Add, Button, gShowRecentItems, SHOW RECENT ITEMS ; Links to recent items folder in Windows
; BLANK SPACE
Gui, font, s14, Verdana ; Set font
Loop, 6
Gui, Add, Text,,
; RE-INDEX BUTTON
Gui, font, s10, Verdana ; Set font
Gui, Add, Button,, &Re-Index ; The label Re-Index (if it exists) will be run when the button is pressed.
; SHOW THE DATE/TIME OF THE LAST RE-INDEX
FileGetTime, LastIndexTime, %INDEX_FILE%, M ; get last modified timestamp
; Format modified date and time
LastIndexDays := DateInDays(LastIndexTime)
TodayDays := DateInDays(0)
LastIndexDaysAgo := TodayDays - LastIndexDays
FormatTime, TM_TIME, %LastIndexTime%, h:mm tt
if (LastIndexDaysAgo = 0)
LastIndexDaysAgo := "today at " . TM_TIME
Else if (LastIndexDaysAgo = 1)
LastIndexDaysAgo := "yesterday at " . TM_TIME
else
LastIndexDaysAgo .= " days ago"
Gui, add, text,, Last indexed %LastIndexDaysAgo% ; display modified date
FormatTime, MatchedFileModified_DayOfYear, %MatchedFileModified%, YDay
FormatTime, MatchedFileModified_Year, %MatchedFileModified%, yyyy
ModifiedDays := (MatchedFileModified_Year * 365) + MatchedFileModified_DayOfYear
FormatTime, CurrentDayOfYear,, YDay
FormatTime, CurrentYear,, yyyy
; GUI
Gui, Add, Text, ym w50 ; empty column
Gui, font, s8 bold, Verdana ; Set font
Gui, Add, Text, ym w300, SEARCH OPTIONS
Gui, font, norm ; Set font size
Gui, Add, Text, w300, `n1) FILE TYPE`n Example: '`*.pdf'`n Finds PDF files`n`n2) EXCLUDE TEXT`n '-pdf'`n Exclude any PDF file`n`n3) RECENTLY MODIFIED`n '*days5 `*.pdf'`n Finds PDF files modified in the past 5 days`n`n4) QUOTED TEXT`n "staff meeting"`n Finds 'April Staff Meeting.pdf' but NOT 'April Staff and Member Meeting.pdf'`n`n5) COMBINATIONS`n '2012 "staff meeting" `*.pdf days2'`n Find PDF files containing "2012" and "staff meeting" that were modified in the last two days
Gui, Add, Text, ym
Gui, font, s14, Verdana ; Set font
Loop, 7
Gui, Add, Text,,
Gui, font, s10, Verdana ; Set font
Gui, Add, Button,, &Cancel ; The label CANCEL (if it exists) will be run when the button is pressed.
Gui, Show,, FILE SEARCH
; End of auto-execute section. The script is idle until the user does something.
return
ShowRecentItems:
Gui, Destroy
Run, C:\Users\cbrackett\AppData\Roaming\Microsoft\Windows\Recent
ExitApp
Return
SearchInternet:
Gui, Submit ; Save the input from the user to each control's associated variable.
Gui, Destroy
WebSearchTerm := SearchTerm
#Include SearchInternet.ahk
ExitApp
Return
GuiClose:
ButtonCancel: ; If CANCEL is clicked
GuiEscape: ; If ESCAPE is pressed
If (CurrentGUI = "Search") ; if in the search window, go back to the parameters window
{
SearchInProgress = 0
CurrentGUI = "Parameters" ; identify the current gui window
Goto, RefineSearch
}
ExitApp ; if not in the search window, exit
return
ButtonRe-Index: ; REINDEX SEARCH LOCATIONS
Msgbox, 4, RE-INDEX?, Are you sure you want to reindex the database? This may take some time., 10
If ErrorLevel
Goto, GuiClose
IfMsgBox, Yes
{
Run, %A_WorkingDir%\SearchFiles\SearchFilesReIndex.ahk
Goto, EndMacroSearchFiles
}
IfMsgBox, No
return
Return
RefineSearch: ; DESTROY THE SEARCH GUI AND RETURN TO THE PARAMETERS GUI
Cancell:
Gui, Destroy
Goto, StartThisMacro
Return
SearchFiles:
Gui, Submit ; Save the input from the user to each control's associated variable.
GUI, Destroy
Goto, StartSearch
Return
ButtonHiddenButtonOpenFile: ; When user hits enter, open the selected file.
GuiControlGet, FocusedControl, FocusV
FocusedRow := LV_GetNext("", "Focused")
; If no file is selected, do nothing.
if FocusedRow = 0
return
; Get the name and path of the currently selected file
LV_GetText(LinkFileName, FocusedRow, 1)
LV_GetText(LinkFilePath, FocusedRow, 5)
; If the selected file exists, open it and then close the search program
IfExist, %LinkFilePath%\%LinkFileName%
{
Run, %LinkFilePath%\%LinkFileName% ; Open the selected file
CurrentGUI := ; Clear the CurrentGUI variable to allow the search program to completely close
Goto, GuiClose ; Close the search program
}
; If the file does not exist, display an informational message
IfNotExist, %LinkFilePath%\%LinkFileName%
Msgbox, The file no longer exists or has been moved.
Return
MyListView:
If A_GuiEvent = DoubleClick ; IF USER DOUBLE CLICKS A SEARCH RESULT, OPEN THE FILE
{
LV_GetText(LinkFileName, A_EventInfo, 1)
LV_GetText(LinkFilePath, A_EventInfo, 5)
IfExist, %LinkFilePath%\%LinkFileName%
Run, %LinkFilePath%\%LinkFileName% ; opens the file
IfNotExist, %LinkFilePath%\%LinkFileName%
Msgbox, The file no longer exists or has been moved.
}
If A_GuiEvent = RightClick ; IF USER RIGHT CLICKS A SEARCH RESULT, OPEN THE FILE LOCATION
{
LV_GetText(LinkFilePath, A_EventInfo, 5) ; Get the path of the selected file.
; If the file exists and has a path, open the file directory
IfExist, %LinkFilePath%
Run, %LinkFilePath%
; If the file does not exist or there is not path, display an informational message.
IfNotExist, %LinkFilePath%
Msgbox, The file no longer exists or has been moved.
}
Return
EndMacroSearchFiles:
ExitApp
Push:
GuiControl, , lvl, 1
Return
StartSearch:
; Begin timing the search
SearchStartTime := StartTimer()
; Remember the search parameters to use as a default if "refine search" is clicked
LastSearchTerm := SearchTerm
; Save the search parameters to file to use as a default the next time the search program is run
IfExist, %LAST_SEARCH_FILE%
FileDelete, %LAST_SEARCH_FILE%
FileAppend, %LastSearchTerm%, %LAST_SEARCH_FILE%
; Identify the current gui window
CurrentGUI := "Search"
; REMOVE '*' FROM FILE EXTENSION SEARCHES (EX. '*.pdf' IS CONVERTED TO '.pdf')
IfInString, SearchTerm, *.
StringReplace, SearchTerm, SearchTerm, *., ., All
; SEPARATE SEARCH TERMS INTO INDIVIDUAL WORDS, KEEP QUOTED TEXT TOGETHER
SearchTermCount :=
Loop, Parse, SearchTerm, """", %A_Space%
{
If (A_Index / 2) <> ROUND( A_Index / 2, 0)
Loop, Parse, A_Loopfield, %A_SPACE%, %A_Space%
{
SearchTermCount++
SearchTerms%SearchTermCount% := A_Loopfield
If (SearchTerms%SearchTermCount% = "")
SearchTermCount--
}
Else
{
SearchTermCount++
SearchTerms%SearchTermCount% := A_Loopfield
If (SearchTerms%SearchTermCount% = "")
SearchTermCount--
}
}
; BUILD & DISPLAY SEARCH RESULTS GUI
Gui, Add, Text,,SEARCHING FOR...%SearchTerm%%FilterText% ; Name the GUI window (creates a header name).
Gui, Font, S12 ; Set font for the GUI.
Gui, Add, ListView, AltSubmit left r20 w1500 h700 gMyListView, Name|Ext.|MB|Modified|Location ; Create columns and set formatting.
Gui, Add, StatusBar,, Bar's starting text (omit to start off empty). ; Create a status bar.
Gui, Add, Text,,Press ESCAPE to cancel. ; Add text in the GUI.
SB_SetText("Search in Progress") ; Update GUI status bar
gui, font, s16 ; Set the font for the buttons.
Gui, Add, Button, gRefineSearch, &REFINE SEARCH ; Create a "Refine Search" button.
Gui, Add, Progress, vlvl -Smooth 0x8 w250 h18
SetTimer, Push, 45
; Gui, Add, Button, gGuiClose xp+250, &CLOSE ; Create a "Close" button.
Gui, Add, Button, Hidden Default h0, HiddenButtonOpenFile ; Default action if enter is hit, to open selected file
Gui, Show ; Show the newly created GUI objects.
; SEARCH INDEX FILE FOR MATCHES AND DISPLAY IN GUI
ResultsLimited :=
SearchInProgress = 1 ; search in progress until set to zero
Loop, read, %INDEX_FILE%
{
if (SearchInProgress = 0) ; If the search was cancelled, stop searching
return
LineNumber := A_Index
Loop, parse, A_LoopReadLine, CSV
{
NotFoundA :=
If A_Index = 2
{
Loop, %SearchTermCount% ; Search for Unquoted Text
{
ThisSearchCheck :=
BreakOutExclude :=
ThisFileLocationNew := A_LoopField
ThisSearch := SearchTerms%A_INDEX%
; Check if search string starts with "-" and if so use it to exclude files
StringLeft, ThisSearchCheck, ThisSearch, 1
If (ThisSearchCheck = "-")
{
StringTrimLeft, ThisSearch, ThisSearch, 1
BreakOutExclude :=
IfInString, A_LoopField, %ThisSearch%
{
NotFoundA = 1
Break
}
}
Else
IfNotInString, A_LoopField, %ThisSearch%
NotFoundA = 1
}
If (NotFoundA <> 1) ; If a match and no excluded search terms are found..
{
NumberOfResults++
FoundMatch = 1
MatchedFileName := ThisFileLocationNew
LV_ModifyCol() ; Auto-size each column to fit its contents.
LastMatchTime := StartTimer() ; Timestamp of when match was found, used to limit how fast search result counts update on the gui
}
else
Break
}
If A_Index = 3
; GET THE FULL FILE PATH INCLUDING NAME
If (FoundMatch = 1) ; If a match and no excluded search terms are found...
{
FoundMatch :=
StringSplit, FileDetails, A_LoopReadLine, `, ; NEW 12/11/14 edit
Matched_Full_File_Path := A_LoopField ; NEW 2014/12/11 edit
SplitPath, Matched_Full_File_Path, MatchedFilePath, MatchedFileDir, MatchedFileExtension, MatchedFileNameNoExt, MatchedFileDrive
StringUpper, MatchedFileExtension, MatchedFileExtension
}
; GET FILE MODIFIED DATE
If A_Index = 1
MatchedFileModified := A_LoopField
If (A_Index = 4) ; GET FILE SIZE
{
MatchedFileSize := A_LoopField
MatchedFileSize := ROUND((MatchedFileSize / 1024),2)
If (MatchedFileSize = 0)
MatchedFileSize := 0.01
; Update GUI with search results
gui, font, s12 ; format next
FormatTime, MatchedFileModified, %MatchedFileModified%, yyyy-MM-dd HH:mm ; Format modified date for GUI
Gui, Font, S12
LV_Add("", MatchedFileName, MatchedFileExtension,MatchedFileSize,MatchedFileModified,MatchedFileDir) ; Update GUI with search result
LV_ModifyCol() ; Auto-size each column to fit its contents.
If (NumberOfResults = 1)
{
LV_Modify(0, "-Select") ; to deselect all selected rows
LV_Modify(1,"Focus Select")
}
MatchedFileName :=
}
If (NumberOfResults > ResultsLimit)
Break
}
If (NumberOfResults > ResultsLimit)
Break
}
SearchInProgress = 0 ; identify the search as not currently in progress
NumberOfResultsFormatted := ThousandsSep(NumberOfResults)
SB_SetText(ProgressDots . " Matching Files: " . NumberOfResultsFormatted)
; Update GUI with number of results returned
SB_SetText("Matching Files: " . NumberOfResultsFormatted)
; UPDATE GUI WITH NUMBER OF RESULTS RETURNED AND CONFIRM SEARCH COMPLETION
IF (NumberOfResults > ResultsLimit)
ResultsLimited := "RESULTS LIMITED TO " . ResultsLimit . " FILES"
ELSE
SearchResult := "SEARCH COMPLETE"
; Calculate the search time
SearchTimeInSeconds := ROUND( EndTimer(SearchStartTime), 4)
; Hide progress bar when search is complete
GuiControl, Hide, msctls_progress321 ; The ClassNN of the progress bar equals 'msctls_progress321'
; Gui, Font, norm s12 cDA4F49 ; format next
Gui, Font, cDA4F49 s36 ; format next
ResultsLimitedFormatted := ThousandsSep(ResultsLimited)
SB_SetText("Matching Files: " . NumberOfResultsFormatted . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . A_SPACE . ResultsLimitedFormatted . A_SPACE .A_SPACE .A_SPACE .A_SPACE .A_SPACE . A_SPACE .A_SPACE .A_SPACE .A_SPACE .A_SPACE . "Search completed in " . SearchTimeInSeconds . " seconds")
; SB_SetText("Search completed in " . SearchTimeInSeconds . " seconds")
; FORMAT GUI COLUMNS
LV_ModifyCol() ; Auto-size each column to fit its contents.
LV_ModifyCol(3, "Float SortDesc") ; For sorting purposes, indicate that column 3 (file size in MB) is an integer.
LV_ModifyCol(4, "SortDesc")
return
; END START SEARCH
Upvotes: 2