Created
April 11, 2017 04:31
-
-
Save TLMcode/c7bc8bffa421311e0505d5d647bdeb98 to your computer and use it in GitHub Desktop.
Server File Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoTrayIcon | |
PrefFile := A_ScriptDir "\prefs.txt" | |
TCtrlW := 250 | |
if FileExist( PrefFile ) | |
{ | |
FileRead, Prefs, % PrefFile | |
For Each, Pref in ( StrSplit( Prefs, "~" ), SectionObj := {} ) | |
{ | |
PrefArr := StrSplit( Pref, ">>>" ) | |
SectionObj[ PrefArr[ 1 ] ] := PrefArr[ 2 ] | |
} | |
} | |
Gui Font, s8, Arial | |
Gui +ToolWindow +AlwaysOnTop | |
Gui Add, Text,, Find String In Files | |
Gui Add, Text,, Directory | |
Gui Add, Edit, % " vDir r1 w" TCtrlW, % SectionObj.Dir | |
Gui Add, Text,, File Type | |
Gui Add, Edit, % " vType w" TCtrlW, % SectionObj.Type | |
Gui Add, Text,, Search Term | |
Gui Add, Edit, % " vStr w" TCtrlW, % SectionObj.String | |
Gui Font, s26, Arial | |
Gui Add, Button, vsBtn Section, Search | |
GuiControlGet, sBtnPos, Pos, sBtn | |
Gui Add, Button, % "xp" sBtnPosW+10, Stop | |
Gui Font, s8, Arial | |
Gui Add, Text, % "xm vDisp w" TCtrlW, Status: | |
Gui Show | |
Return | |
F2::Reload | |
ButtonSearch: | |
Gui Submit, NoHide | |
if ( Dir = "" || Str = "" || Type = "" ) | |
{ | |
MsgBox, 0x10, Whoops!, % ( ( Dir = "" && Str = "" && Type = "" ) ? "Fields" : ( Dir = "" ) ? "Directory" : ( Str = "" ) ? "String" : ( Type = "" ) ? "Type" : "" ) " Cannot Be Blank!`nPlease try again!" | |
Return | |
} | |
FileDelete % PrefFile | |
FileAppend % "Dir>>>" Dir "~String>>>" Str "~Type>>>" Type, % PrefFile | |
MatchCount := 0, FileList := "" | |
; ToDo add recursive search option | |
Loop, % Dir "\*." Type | |
{ | |
; ToDo add response for file type not found ( actually don't think I need this as each file will be read 1st anyway ) | |
FileRead, FileContents, % A_LoopFileLongPath | |
if ( Stop = True ) | |
Break | |
if ( !MatchCount ) | |
GuiControl,, Disp, Status: Searching... | |
if InStr( FileContents, Str ) | |
{ | |
MatchCount += 1 ; Matches | |
GuiControl,, Disp, % "Status: Found " MatchCount " Match" ( MatchCount > 1 ? "es" : "" ) | |
FileList .= MatchCount ": " Str " Found in: " A_LoopFileLongPath "`n" | |
} | |
} | |
; ToDo add checkbox list of files to open | |
Msgbox % ( FileList = "" ) ? 0x10 : 0x0, % (( FileList = "" ) ? "No" : "Some" ) "thing Found!" | |
, % ( Stop = True ) ? ( " Search Cancelled!", Stop = False ) | |
: ( FileList = "" ) ? "" Str "" " not found in any " type " files!" | |
: "String: " Str " Found in " MatchCount " File" ( MatchCount > 1 ? "s" : "" ) "`n" FileList | |
GuiControl,, Disp, Status: | |
Return | |
ButtonStop: | |
Stop := True | |
Return | |
GuiClose: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment