使用Autohotkey索引和搜索文件

时间:2015-12-10 22:48:36

标签: indexing autohotkey hotkeys

在工作时,禁用Windows文件索引。作为一种解决方法,我使用Autohotkey v1.1.22.00创建了3个脚本,以便(1)当我快速按两次Control键时允许启动搜索用户界面,(2)我选择的位置中的索引文件,(3)快速使用关键字搜索文件,以及(4)使用搜索界面启动Google网络搜索。我在下面发布了我的脚本作为答案。

我很想知道这是否适用于其他任何人,或者其他人是否可以改善这一点或提供更好的解决方案。

谢谢!

2 个答案:

答案 0 :(得分:0)

以下是我一起使用的三个脚本,用于索引和快速搜索大约150,000个网络文件。我安排指数每天早上运行。它会创建一个CSV文件,用于存储上次修改的文件名,位置,大小和日期/时间,以便在结果顶部显示最近修改过的文件。

索引按照最近修改过的文件修改的日期/时间进行预先排序。这允许脚本使用我最常使用的最近修改的文件快速返回结果,而完整的结果通常需要6-10秒。

(1)当我快速按两次Control键时,允许启动搜索用户界面,(2)我选择的位置的索引文件,(3)使用关键字快速搜索文件,以及(4)使用搜索用于启动Google网络搜索的界面。

这是一个脚本,用于设置双击CTRL作为启动搜索UI的热键。更改var“SearchAppPath”的值以使AHK文件的位置与搜索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

下一个脚本索引文件。它可以手动运行,也可以在搜索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

最终脚本包含实际的搜索用户界面。

; 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

答案 1 :(得分:0)

最后一个脚本包含网络搜索功能,只需将浏览器启动到Google搜索中即可。

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

}