Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Alpha Search - in-file string search tool


  • Please log in to reply
13 replies to this topic
Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hello all
it is sometimes needed to find some specific data in your scripts store or project's sources of any kind. Some people have to use tools embedded in different file managers, but i don't use them at all, so i decided to write a small searching tool myself, which is slowly grown up and with few improvments for public use here it is...

Any suggestions/improvments/criticism are welcome :)

Alpha Search

Features:
[*:4cbezcbz]RegEx or Simple search with optional MatchCase parameter
[*:4cbezcbz]History for both - search dir and pattern
[*:4cbezcbz]Double click on any found line to open it in Notepad/Notepad++/Scite
[*:4cbezcbz]All options saving on gui closing
[*:4cbezcbz]Cool progress bar and stats just for the sake... :)
Posted Image

Download code - AHK_L required
Download executable


tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
ha. nice. looks quite similar to my personal tool: Image (uses regex aswell. forced.) but wow. judging by the screenshot, yours is MUCH faster then mine :)

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
It looks similar to grep but with a Gui and everything.
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
nice, the best way to find programs you need is to write one yourself and publish it :)

Morpheus
  • Members
  • 475 posts
  • Last active: Oct 21 2014 11:08 AM
  • Joined: 31 Jul 2008
Very Nice! I will be definitely be using this. :D

My only criticism is regarding the screen shot. Your Regex is SOME.*?thing, and the screen shot only shows the word 'something' in the files. It would be better if a result such as 'some silly thing' were shown. Really minor, but it would show the true power of your script.

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
ok ;)

closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
Very nice Deo :)


I only going to change the layout somehow for me it is a bit confusing ( i want to be able to use it even when half sleeping :) )

Maybe changing the search button to a bigger square one.

The speed of the code is surprising!

Thanks for sharing it.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
thank you Deo, like it, good that you have also an ini-file ( keep savings to search from here... )
(I use AHK basic at moment , exe works fine )

@Thanh00

i want to be able to use it even when half sleeping Smile

Thanh00 , don't sleep at work .... 8)

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
thanks for positive feedback, guys! :)
Thanh00
sure, man, change it as you feel better and don't forget to post here ;)

godsstigma
  • Members
  • 222 posts
  • Last active: May 13 2011 03:09 AM
  • Joined: 04 Nov 2008
Well this looks sort of familiar! :D
Really nice job man!

aaffe
  • Members
  • 1045 posts
  • Last active: Jan 16 2014 01:32 PM
  • Joined: 17 May 2007
tidbit, could you please post a link to download your script?
Thanks a lot!

ha. nice. looks quite similar to my personal tool: Image (uses regex aswell. forced.) but wow. judging by the screenshot, yours is MUCH faster then mine :)



tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
aaffe:
/*
Name:     Find Me
Version:  1.5 (Thu May 12, 2011)
Author:     tidbit
Description: Find all matching text/phrases inside of files of a sepecified directory.

right-click: context Menu
esc: stop searching and replacing
ctrl+w: exit the program

*/

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force
SetBatchLines, -1

Menu, copymenu, Add, Copy Text, copymenu
Menu, copymenu, Add, Select All, selmenu
selall:=0

gui, +Default +Resize +minsize

Gui, Add, Edit, x6 y10 w190 h20 vseldir, %A_desktop%
Gui, Add, Button, xp+192 y10 w58 h20 vseldirbtn gbrowse, Browse

Gui, Add, Text, x6 yp+22 w60 h20 , Extensions:
Gui, Add, Edit, xp+62 yp w188 h20 vexts gext, txt`,ahk`,htm`,html

Gui, Add, Text, x6 yp+22 w60 h20 , Find:
Gui, Add, Edit, xp+62 yp w108 h20 vword, Regex is Enabled. Case Insensitive
Gui, Add, Button, xp+110 yp w20 h20 vwordhelp gregexhelp,?
Gui, Add, Button, xp+22 yp w58 h20 vwordsearch gsearch +Default, Search

Gui, add, Checkbox, x6 yp+22 gusereplace vusereplace, Replace?
Gui, Add, Edit, xp+72 yp w120 h20 vreplace +Disabled, Regex is Enabled. Case Insensitive.
Gui, Add, Button, xp+122 yp w58 h20 vreplacebtn greplace, Replace

Gui, Add, ListView, x6 yp+22 w250 h210 vlist glistview Count5000 +Checked, File|Line|Offset|Sample

LV_ModifyCol(1, "80 Left")
LV_ModifyCol(2, "40 Integer Center")
LV_ModifyCol(3, "40 Integer Center")
LV_ModifyCol(4, "250 Left")

Gui, Add, StatusBar,,
Gui, Show, AutoSize, Find Me`, By: tidbit
SB_SetText("Awaiting Action.", 1, 0)
Gosub, guisize
Return

Guisize:
	SB_SetParts((A_GuiWidth/3)+30, A_GuiWidth/3, A_GuiWidth/3)
	SB_SetText("Press Escape to abort a search.", 2, 0)
	SB_SetText("Right-click to copy text.", 3, 0)

	Anchor("seldir", "w")
	Anchor("seldirbtn", "x")

	Anchor("exts", "w")

	Anchor("word", "w")
	Anchor("wordhelp", "x")
	Anchor("wordsearch", "x")

	Anchor("replace", "w")
	Anchor("replacebtn", "x")

	Anchor("list", "wh")
Return




usereplace:
	gui, Submit, NoHide
	If (usereplace==1)
		guiControl, Enable, replace
	Else
		guiControl, Disable, replace
Return

replace:
	gui, Submit, NoHide
	If (usereplace==0)
		Return

	SB_SetText("Replacing... ", 1, 0)

	Loop % LV_GetCount()
	{

		If (getkeystate("esc","p"))
			Break

		SendMessage, 4140, A_index - 1, 0xF000, SysListView321  ; 4140 is LVM_GETITEMSTATE.  0xF000 is LVIS_STATEIMAGEMASK.
		isChecked := (ErrorLevel >> 12) - 1
		; isChecked := LV_GetNext(iteration, "Checked")

		If (isChecked==0)
			Continue

		LV_GetText(line, A_index, 2)
		LV_GetText(file, A_index, 1)
		LV_Modify(A_Index, "-Check")

		SB_SetText("Replacing in: " file, 1, 0)
		; msgbox %A_index% - %iteration%: c%ischecked% - l%line% - f%file%

		TF_RegExReplaceInLines("!" seldir "\" file, line, line, word, replace)
	}

	SB_SetText("Awaiting Action.", 1, 0)
Return


ext:
	gui, Submit, NoHide
	If exts Contains .,%A_Space%
	{
		StringReplace, exts, exts, .,, All
		StringReplace, exts, exts, %A_Space%,, All
		GuiControl, text, exts, %exts%
	}
Return


browse:
	FileSelectFolder, seldir, *%seldir%, 3, Select a folder.
	If (RegExMatch(seldir, "^\s*$"))
		Return
	Else
		GuiControl, , seldir, %seldir%
Return

listview:
	If (A_GuiEvent=="DoubleClick")
	{
		LV_GetText(Filetorun, A_EventInfo)
		If (filetorun=="File")
			Return
		run, %seldir%\%filetorun%
	}
Return


search:
	gui, Submit, NoHide
	LV_ModifyCol(4, "AutoHdr", "Sample: (0)")

	If (RegExMatch(seldir, "^\s*$"))
		Return

	LV_Delete()
	selall:=0
	Loop,%seldir%\*.*
	{
		If A_LoopFileExt in %exts%
		{
			max:=A_Index
			SB_SetText("Counting files: "A_Index, 1, 0)
		}
		Continue
	}

	Loop,%seldir%\*.*
	{
		If (getkeystate("esc","p"))
			Break

		; SB_SetText("Searching file: " A_Index, 1, 0)
		If A_LoopFileExt in %exts%
		{
			file:=A_LoopFileFullPath
			fileName:=A_LoopFileName
			SB_SetText("file: "A_Index "/" max " -- " file, 1, 0)
		}
		Else
			Continue
		
		Loop, read, %file%
		{
			If (getkeystate("esc","p"))
				Break

			If (pos:=RegExMatch(A_LoopReadLine, "i`n)" word))
			{
				;~ pos:=RegExMatch(A_LoopReadLine, word)
				If (pos==-1)
					pos=NULL
				LV_Add("", fileName, A_index, pos, unHTM(A_LoopReadLine))
				;~ LV_ModifyCol(2, "AutoHdr")
				;~ LV_ModifyCol(3, "AutoHdr")
				LV_ModifyCol(4, "AutoHdr", "Sample: (" LV_GetCount() ")")
			}
			LV_ModifyCol(4, "AutoHdr", "Sample: (" LV_GetCount() ")")
		}
	}
	LV_ModifyCol(1, "Auto")
	LV_ModifyCol(4, "Auto")
	SB_SetText("Awaiting Action.", 1, 0)
Return


regexhelp:
	Gui, 11: Destroy
	Gui, 11: Default
	help=
	(
.	Matches any character.	cat. matches catT and cat2 but not catty
[]	Bracket expression. Matches one of any characters enclosed.	gr[ae]y matches gray or grey
[^]	Negates a bracket expression. Matches one of any characters EXCEPT those enclosed.	1[^02] matches 13 but not 10 or 12
[-]	Range. Matches any characters within the range.	[1-9] matches any single digit EXCEPT 0
?	Preceeding item must match one or zero times.	colou?r matches color or colour but not colouur
()	Parentheses. Creates a substring or item that metacharacters can be applied to	a(bee)?t matches at or abeet but not abet
{n}	Bound. Specifies exact number of times for the preceeding item to match.	[0-9]{3} matches any three digits
{n,}	Bound. Specifies minimum number of times for the preceeding item to match.	[0-9]{3,} matches any three or more digits
{n,m}	Bound. Specifies minimum and maximum number of times for the preceeding item to match.	[0-9]{3,5} matches any three, four, or five digits
|	Alternation. One of the alternatives has to match.	July (first|1st|1) will match July 1st but not July 2
[:alnum:]	alphanumeric character	[[:alnum:]]{3} matches any three letters or numbers, like 7Ds
[:alpha:]	alphabetic character, any case	[[:alpha:]]{5} matches five alphabetic characters, any case, like aBcDe
[:blank:]	space and tab	[[:blank:]]{3,5} matches any three, four, or five spaces and tabs
[:digit:]	digits	[[:digit:]]{3,5} matches any three, four, or five digits, like 3, 05, 489
[:lower:]	lowercase alphabetics	[[:lower:]] matches a but not A
[:punct:]	punctuation characters	[[:punct:]] matches ! or . or , but not a or 3
[:space:]	all whitespace characters, including newline and carriage return	[[:space:]] matches any space, tab, newline, or carriage return
[:upper:]	uppercase alphabetics	[[:upper:]] matches A but not a
//	Default delimiters for pattern	/colou?r/ matches color or colour
i	Append to pattern to specify a case insensitive match	/colou?r/i matches COLOR or Colour
\b	A word boundary, the spot between word (\w) and non-word (\W) characters	/\bfred\b/i matches Fred but not Alfred or Frederick
\B	A non-word boundary	/fred\B/i matches Frederick but not Fred
\d	A single digit character	/a\db/i matches a2b but not acb
\D	A single non-digit character	/a\Db/i matches aCb but not a2b
\n	The newline character. (ASCII 10)	/\n/ matches a newline
\r	The carriage return character. (ASCII 13)	/\r/ matches a carriage return
\s	A single whitespace character	/a\sb/ matches a b but not ab
\S	A single non-whitespace character	/a\Sb/ matches a2b but not a b
\t	The tab character. (ASCII 9)	/\t/ matches a tab.
\w	A single word character - alphanumeric and underscore	/\w/ matches 1 or _ but not ?
\W	A single non-word character	/a\Wb/i matches a!b but not a2b
	)

	Gui, 11: add, text, y6 x6, Basic Regex Help
	Gui, 11:add, ListView, y26 x6 w450 r25 vlist, Key|Description|Example


	Loop, Parse, help, `n
	{
		StringSplit, col, A_LoopField, %A_Tab%
		LV_Add( "", col1, col2, col3)
	}

	LV_ModifyCol(1, "Auto")
	LV_ModifyCol(2, 200)
	LV_ModifyCol(3, "Auto")

	gui, 11: show, x45 , Regex Help
Return



GuiContextMenu:
	If (A_GuiControl!="list")
		return
	RCrow:=A_EventInfo ; Right-Clicked row
	Menu, copymenu, Show, %A_GuiX%, %A_GuiY%
return

copymenu:
	LV_GetText(copytext, RCrow, 4)
	Clipboard:=copytext
Return

selmenu:
	selall:=!selall
	if (selall==1)
		LV_Modify(0, "Check")
	else
		LV_Modify(0, "-Check")
Return


; thanks SKAN! http://www.autohotkey.com/forum/viewtopic.php?t=51342&highlight=remove+html
UnHTM( HTM ) {   ; Remove HTML formatting / Convert to ordinary text   by SKAN 19-Nov-2009
 Static HT,C=";" ; Forum Topic: www.autohotkey.com/forum/topic51342.html  Mod: 16-Sep-2010
 IfEqual,HT,,   SetEnv,HT, % "ááââ´´ææàà&ååãã&au"
 . "mlä&bdquo„¦¦&bull•ç縸¢¢&circˆ©©¤¤&dagger†&dagger‡°"
 . "°÷÷ééêêèèððëë&euro€&fnofƒ½½¼¼¾¾>>&h"
 . "ellip…ííîî¡¡ìì¿¿ïï««&ldquo“&lsaquo‹&lsquo‘<<&m"
 . "acr¯&mdash—µµ··  &ndash–¬¬ññóóôô&oeligœòò&or"
 . "dfªººøøõõöö¶¶&permil‰±±££"""»»&rdquo”®"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš§§­ ¹¹²²³³ßßþþ&tilde˜&tim"
 . "es×&trade™úúûûùù¨¨üüýý¥¥ÿÿ"
 $ := RegExReplace( HTM,"<[^>]+>" )               ; Remove all tags between  "<" and ">"
 Loop, Parse, $, &`;                              ; Create a list of special characters
   L := "&" A_LoopField C, R .= (!(A_Index&1)) ? ( (!InStr(R,L,1)) ? L:"" ) : ""
 StringTrimRight, R, R, 1
 Loop, Parse, R , %C%                               ; Parse Special Characters
  If F := InStr( HT, L := A_LoopField )             ; Lookup HT Data
    StringReplace, $,$, %L%%C%, % SubStr( HT,F+StrLen(L), 1 ), All
  Else If ( SubStr( L,2,1)="#" )
    StringReplace, $, $, %L%%C%, % Chr(((SubStr(L,3,1)="x") ? "0" : "" ) SubStr(L,3)), All
Return RegExReplace( $, "(^\s*|\s*$)")            ; Remove leading/trailing white spaces
}

#IfWinActive, Find Me`, By: tidbit
^w::
GuiClose:
ExitApp
#IfWinActive
requires Anchor, by Polythene. or you can just comment out the window resizing section.
It's a personal script. don't expect me to fix any bugs or maintain it.
edit:: just updated it. it's a bit faster now.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


aaffe
  • Members
  • 1045 posts
  • Last active: Jan 16 2014 01:32 PM
  • Joined: 17 May 2007
Thank you!

Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009
Deo and tidbit, you should both add LV_SortArrow to your scripts. :wink: