Multiple Variables In Message Box Topic is solved
Re: Multiple Variables In Message Box
Hmmmm ... still a couple of stray results. Still testing.
Re: Multiple Variables In Message Box
Just out of curiosity, another approach:
Code: Select all
#SingleInstance, Force
SetWorkingDir, A_ScriptDir
;For example, if I had a file called "Joe Smith - Letter from Acme Hardware.pdf"
;I'd like to be able to enter "Smith" in the first space in the message box and "Acme" in the second space,
;and have it find the file even those two words are not next to the other in the file path name.
InputBox, str, Directory filter, Enter the filter.,, 300, 125
p := StrSplit(str, A_Space)
Loop, Files,% A_ScriptDir "\*.pdf" ; change that path accordingly + the option to search subdirectories
{ SplitPath, A_LoopFileName,,,, OutNameNoExt
i:=0
for key in p {
InStr(OutNameNoExt, p[A_Index]) ? i++ : i
if (i = p.Count()) {
list .= A_LoopFileName "`n"
i:=0
}
}
}
MsgBox % RTrim(list,"`n")
Re: Multiple Variables In Message Box
My testing shows that both Mikeyww's second script and Bobo's script work 100% accurately when there are a lot of search words, but have errors in them when there are just one or two search words. The two scripts have the exact same errors when there are, for example, two search words.
I don't have the same errors when I use a script with multiple input boxes. And I believe that has the advantage of being able to "chunk" search terms. For example, if I type "red apples" in the first input box, "sale" in the second" and "August" in the third then it would find files and folder names where the words "red apples" are right next to each other, and "sale" and "August" also appear, but not files/folder names where "red" is separated from "apples". For example, it would find Red Apples Taste Good When They're On Sale in July or August.pdf, but not Red Is My Favorite Color and Apples Taste Good When They're On Sale in July or August.pdf.
Being able to chunk in this type of search is sort of like using quotation marks in a Google search: "red apples" sale august https://www.google.com/search?q=%22red+ ... e&ie=UTF-8
But since it seems impossible to set up multiple input areas in a single inputbox, the ideal still seems to have a child gui like in my not-working script I posted. But not sure...
I don't have the same errors when I use a script with multiple input boxes. And I believe that has the advantage of being able to "chunk" search terms. For example, if I type "red apples" in the first input box, "sale" in the second" and "August" in the third then it would find files and folder names where the words "red apples" are right next to each other, and "sale" and "August" also appear, but not files/folder names where "red" is separated from "apples". For example, it would find Red Apples Taste Good When They're On Sale in July or August.pdf, but not Red Is My Favorite Color and Apples Taste Good When They're On Sale in July or August.pdf.
Being able to chunk in this type of search is sort of like using quotation marks in a Google search: "red apples" sale august https://www.google.com/search?q=%22red+ ... e&ie=UTF-8
But since it seems impossible to set up multiple input areas in a single inputbox, the ideal still seems to have a child gui like in my not-working script I posted. But not sure...
Re: Multiple Variables In Message Box
My script found a file containing "red" and "apples". Will your problem examples & file list remain a secret?
Re: Multiple Variables In Message Box
Mikeyww, I'll send you my test results via private message. Thanks.
Re: Multiple Variables In Message Box
Sure, OK, or again, OK to post some dummy file names and examples of what input did not work for them.
Re: Multiple Variables In Message Box
For the sake of anyone reading this thread, Mikeyww explained to me through a private message that I was misunderstanding the search results, and that his second script works perfectly. D'oh! My mistake.
Thank you Mikeyww for writing a great script, and also for educating me about how I was confused.
Incidentally, I believe Bobo's script works also.
Thank you Mikeyww for writing a great script, and also for educating me about how I was confused.
Incidentally, I believe Bobo's script works also.
Re: Multiple Variables In Message Box Topic is solved
No trouble. This one is actually adapted from BoBo, for words.
Code: Select all
pathList := [StrReplace(A_Desktop, "Desktop", "Documents"), A_ScriptDir]
InputBox, str, Word filter, Enter the filter.,, 300, 125
If (ErrorLevel || str = "")
Return
p := StrSplit(str, " ")
For each, filePath in pathList
Loop, Files, %filePath%\*, FDR
{ SplitPath, A_LoopFileName,,,, fnBare
i = 0
For each, word in p
i += RegExMatch(fnBare, "i)\b\Q" word "\E\b") > 0 ; Matches words rather than any text
list .= i = p.Count() ? A_LoopFilePath "`n" : ""
}
MsgBox, 64, Matches, % Trim(list, "`n")
Re: Multiple Variables In Message Box
Works like a charm. Thank you for all of your help!
Re: Multiple Variables In Message Box
Mikeyww, I'm sorry but I'm having trouble changing the message box at the end of your script into a list in a gui, so I can display the results in a list. Here's what I'm trying:
This isn't working. What am I doing wrong?
Code: Select all
Gui, Add, ListBox, vMyList x16 y24 w1500 h1000 ; creates the basic gui
Gui, Show,, Test
Gui Font
pathList := ["C:\Users\PATH\OneDrive\Documents\"] ; this is the start of your excellent script
InputBox, filter, Directory filter, Enter the filter.,, 300, 125
If (ErrorLevel || filter = "")
Return
wordList := StrSplit(filter, " ")
For each, filePath in pathList
Loop, Files, %filePath%\*, FDR
{ include := True
For every, word in wordList
If !Instr(A_LoopFileName, word) {
include := False
Break
}
list .= include ? (list > "" ? "`n" : "") A_LoopFilePath : ""
}
GuiControl,, MyList, %list% ; Here's where I'm trying to list the results in my GUI
Gui, Show
Return
Re: Multiple Variables In Message Box
An example is below.
Explained: ListBox
Code: Select all
pathList := [StrReplace(A_Desktop, "Desktop", "Documents"), A_ScriptDir]
InputBox, str, Word filter, Enter the filter.,, 300, 125
If (ErrorLevel || str = "")
Return
p := StrSplit(str, " ")
For each, filePath in pathList
Loop, Files, %filePath%\*, FDR
{ SplitPath, A_LoopFileName,,,, fnBare
i = 0
For each, word in p
i += RegExMatch(fnBare, "i)\b\Q" word "\E\b") > 0 ; Matches words rather than any text
list .= i = p.Count() ? A_LoopFilePath "|" : ""
}
Gui, Font, s10
Gui, Add, ListBox, w700 r10, % Trim(list, "|")
Gui, Show,, Matches
The last parameter is a pipe-delimited list of choices such as Choice1|Choice2|Choice3.
Re: Multiple Variables In Message Box
Mikeyww,
Your script works like a charm to list the results in my GUI. But for some reason, I can't get it to take actions on the selected list result.
For example, one of my buttons is supposed to open the selected file or folder from the list, but it is instead just opening my MyDocs folder. Here's my script so far:
When I use a MsgBox to display %pathList%%Selection%" it shows the right filepath for the selected file or folder. But for some reason it won't open it through Explorer.
What am I doing wrong?
Your script works like a charm to list the results in my GUI. But for some reason, I can't get it to take actions on the selected list result.
For example, one of my buttons is supposed to open the selected file or folder from the list, but it is instead just opening my MyDocs folder. Here's my script so far:
Code: Select all
pathList := ["C:\Users\path\OneDrive\Documents\"]
Gui, Add, ListBox, vMyList x16 y24 w1500 h1000 ; creates the basic gui
Gui, Show,, Test
Gui Font
Gui Add, Button, x1 y1 w75 h23 gOpenFolder, Open
InputBox, str, Word filter, Enter the filter.,, 300, 125
If (ErrorLevel || str = "")
Return
p := StrSplit(str, " ")
For each, filePath in pathList
Loop, Files, %filePath%\*, FDR
{ SplitPath, A_LoopFileName,,,, fnBare
i = 0
For each, word in p
i += RegExMatch(fnBare, "i)\b\Q" word "\E\b") > 0 ; Matches words rather than any text
list .= i = p.Count() ? A_LoopFilePath "|" : ""
}
Gui, Font, s10
Gui, Add, ListBox, w700 r10, % Trim(list, "|")
Gui, Show,, Matches
GuiControl,, MyList, %list%
Gui, Show
Return
OpenFolder:
GuiControlGet, Selection,, MyList
Run, Explorer "%pathList%%Selection%"
Gui , Hide
Return
What am I doing wrong?
Re: Multiple Variables In Message Box
You can debug your script by displaying values of variables & functions. That makes the process fast and easy, and it requires no additional knowledge about AutoHotkey. In your script, pathList is an array, not a text string. Your ListBox includes the full path as shown, so you would not add a path to it.
Code: Select all
filePath := StrReplace(A_Desktop, "Desktop", "Documents")
InputBox, str, Word filter, Enter the filter.,, 300, 125
If (ErrorLevel || str = "")
Return
Loop, Files, %filePath%\*, FDR
{ SplitPath, A_LoopFileName,,,, fnBare
i = 0
For each, word in p := StrSplit(str, " ")
i += RegExMatch(fnBare, "i)\b\Q" word "\E\b") > 0 ; Matches words rather than any text
list .= i = p.Count() ? A_LoopFilePath "|" : ""
}
Gui, Font, s10
Gui, Add, ListBox, w700 r30 vsel, %list%
Gui, Add, Button , wp Default , Open
Gui, Show,, Matches
Return
ButtonOpen:
Gui, Submit
Run, %sel%
Return
GuiEscape:
GuiClose:
ExitApp
Re: Multiple Variables In Message Box
Thank you, Mikeyww ... I greatly appreciate your help!
Re: Multiple Variables In Message Box
Bobo, Mikeyww and everyone,
After tinkering around for a couple of months, I've finally used your scripts to get search results of file and folder names (1) for search input of partial words and (2) for full words.
Is there any way to highlight the search strings when searching for partial words, the way that the Everything app does? To demonstrate what I mean, here's a screenshot of results from my AHK script (where nothing is bolded related to the search string "tes" in the results list, so not as useful): And here's a screenshot from a similar results from Everything (where the search string "tes" is bolded within the results list, so I can quickly locate the search string within the results to see if it's what I'm looking for ).
Thanks!
By the way, the code I'm using (ignoring all of the buttons and subroutines) is as follows:
After tinkering around for a couple of months, I've finally used your scripts to get search results of file and folder names (1) for search input of partial words and (2) for full words.
Is there any way to highlight the search strings when searching for partial words, the way that the Everything app does? To demonstrate what I mean, here's a screenshot of results from my AHK script (where nothing is bolded related to the search string "tes" in the results list, so not as useful): And here's a screenshot from a similar results from Everything (where the search string "tes" is bolded within the results list, so I can quickly locate the search string within the results to see if it's what I'm looking for ).
Thanks!
By the way, the code I'm using (ignoring all of the buttons and subroutines) is as follows:
Code: Select all
BasePath1 := "C:\Users\myname\DOWNLOADS\"
BasePath2 := "C:\Users\myname\OneDRIVE\Documents\"
InputBox, str, Word filter, Enter the filter.,, 300, 125
p := StrSplit(str, A_Space)
loop, Files, % BasePath1 "*.*", FDR
{ SplitPath, A_LoopFileName,,,, OutNameNoExt
i:=0
for key in p {
InStr(OutNameNoExt, p[A_Index]) ? i++ : i
if (i = p.Count()) {
; list .= A_LoopFileName "`n"
list .= i = p.Count() ? A_LoopFilePath "|" : ""
i:=0
}
}
}
loop, Files, % BasePath2 "*.*", FDR
{ SplitPath, A_LoopFileName,,,, OutNameNoExt
i:=0
for key in p {
InStr(OutNameNoExt, p[A_Index]) ? i++ : i
if (i = p.Count()) {
; list .= A_LoopFileName "`n"
list .= i = p.Count() ? A_LoopFilePath "|" : ""
i:=0
}
}
}
Gui, Add, ListBox, x16 y24 w1500 h1000 vListBox_ClList, %list%
Gui, Show,, Test
Gui Font
Re: Multiple Variables In Message Box
You could probably do it with HTML in an ActiveX control. BoBo may have some better ideas.