Incremental Search of Files and Folders

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AlFlo
Posts: 345
Joined: 29 Nov 2021, 21:46

Incremental Search of Files and Folders

Post by AlFlo » 06 Dec 2022, 12:04

I have a script which searches for client names within the names of folders and files in my Clients folder, and then lets me manipulate documents within those files. It pops up an input box, where I can type any client name (first or last name, but it has to be all letters in the name), and then - when I press Ok - it lists all folders and files which have that name in them.

I'm wondering if I can instead do an incremental search (https://en.wikipedia.org/wiki/Incremental_search) on those folders and files. Specifically, if my client's name is Jamie Smith, instead of typing "Jamie" or "Smith" in the input box and then pressing ok, can I script a search where if I type in "J" it pulls up all clients with J in their name (e.g. Jamie Smith, Raj Patel, Fred Mijo, etc.), and then if I type in "a" it lists all clients with Ja in their name, and then if I type "m" it lists all clients with jam in their name, etc, with the list narrowing with every additional letter I type.

Here's my current script:

Code: Select all

Gui, Add, ListBox, vListBox_ClList x16 y24 w1600 h1000
Gui, Show,, Test
Gui Font
Gui Add, Button ; a bunch of buttons here

BasePath := "C:\Clients\"
FileList := ""
InputBox, Filter, Directory Filter, Filter?:,, 240, 130, 800, 1
loop, Files, % BasePath "*.*", DR
    if InStr(A_LoopFileFullPath, Filter)
        FileList .= A_LoopFileFullPath "|"
FileList := RTrim(FileList, "|")
Sort, FileList, D|
FileList := StrReplace(FileList, BasePath)
GuiControl,, ListBox_ClList, %FileList%

Gui, Show
return

; A bunch of subroutines run by pressing buttons here

GuiEscape:
GuiClose:
Return
I'm using AHK Version 1.1.34.01.


AlFlo
Posts: 345
Joined: 29 Nov 2021, 21:46

Re: Incremental Search of Files and Folders

Post by AlFlo » 09 Dec 2022, 17:36

Thank you, mikeyww. That is a really cool script!

I'm trying to search through my folder C:\Clients\ . My folder structure is like this: C:\Clients\Jones\Pleadings\IndividualFiles and C:\Clients\Smith\Letters\IndividualFiles.

I modified your script to show this structure, so I know what subfolders I'm looking at (I noted my changes in all caps):

Code: Select all

*/
BasePath := "C:\Clients\" ; I CHANGED THE FOLDER SEARCHED
focusFirst := True  
Gui, Font, s10
Gui, Add, Edit   , w300 vfind    gTyped
Gui, Add, ListBox, wp   vscript  gClik  r20
Gui, Add, Button , wp   Default, Run
Gosub, Filter
Gosub, F3
F3::Gui, Show,, Scripts (F3 = show again)

Typed:
SetTimer, Filter, -300
Return

Filter:
Gui, Submit, NoHide
list = |

loop, Files, % BasePath "*.*", DR
	if InStr(A_LoopFileFullPath, Filter) ; START OF THE PART I CHANGED
		list .= A_LoopFileFullPath "|"
list := RTrim(list, "|")
Sort, list, D| ; END OF THE PART I CHANGED

(focusFirst) && list := StrReplace(list, BasePath)
GuiControl,, script, %list%
GuiControl, % focusFirst && list > "|" ? "Enable" : "Disable", Run
return

; rest of your script goes here
So the folder structure displays nicely.

But my change messed up your incremental search function. In other words, I accidentally broke your script and typing letters into the box no longer changes what is displayed in the list.

Any help greatly appreciated!!!

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Incremental Search of Files and Folders

Post by mikeyww » 09 Dec 2022, 17:46

Code: Select all

If InStr(A_LoopFileFullPath, find)

AlFlo
Posts: 345
Joined: 29 Nov 2021, 21:46

Re: Incremental Search of Files and Folders

Post by AlFlo » 09 Dec 2022, 18:03

Thank you, kind sir! If there is such a thing as karma, you have accumulated billions of positive karma points for all of your help.

Post Reply

Return to “Ask for Help (v1)”