Multiple folder search from Windows context menu

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
MandraK
Posts: 10
Joined: Mon Jan 06, 2020 4:45 pm

Multiple folder search from Windows context menu

Post by MandraK » Mon Jan 06, 2020 5:24 pm

Is there a way to send to everything.exe multiple folders as arguments to search at the same time?

I'm trying to set up a context menu for Everthing.exe to search over multiple folders selected on file explorer, without implementing any shell extension and without the program's own context menu. I need the context menu on a particular location.

Searching multiple folders works directly on Everything by separating the folders with a "|", like this:
"D:\folder1"|"D:\folder2\"
But when I run the context menu, the program gets only the first and last double quotes, like this:
"D:\folder1|D:\folder2\"
I'm using a .vbs file to run everything.exe from the context menu (I do this with many programs).. I've tested the output and the vbscript sends the correct arguments to the program, but it seems the program strips those double quotes... It works fine if only one folder is sent, but when there's more than one I have to manually add the missing double quotes on the program's interface once it's opened..

I include the VBScript file:

Code: Select all

'+============================================
'|  MN_Run for Everything
'|  Date	 2020-01-01 18:57
'|  Last	 2020-01-01 19:52
'|  Author	 Melvin D. Nava <mdnava[at]gmail.com>
'|  URL		 https://www.mdnava.com/
'+============================================
'|  Desc: Search multiple folders from the context menu
'|  Note: Folders as argument are separated by | (everything.exe -p "path1"|"path2"|"path3")
'|        However, for some reason the program strips double quotes for a multiple folder search..
'|  Args: <folders_to_search>
'+============================================
Option Explicit
If WScript.Arguments.Count < 1 Then MsgBox "Missing parameter, nothing to do!.", vbInformation, "Notice" & WScript.Quit()
Dim arrArgs, objFSO, objShell
Set arrArgs		= Wscript.Arguments
Set objFSO		= CreateObject("Scripting.FileSystemObject")
Set objShell	= CreateObject("WScript.Shell")
MN_Run()

Private Sub MN_Run()
	Dim sScriptFolder, sArg, sArgs, nCount
	sScriptFolder = objFSO.GetParentFolderName(objFSO.GetFile(Wscript.ScriptFullName)) & "\"
	nCount = 1
	For Each sArg In arrArgs
		If nCount > 1 Then
			sArgs = sArgs & "|""" & GetFolder(sArg) & """"
		Else
			sArgs = """" & GetFolder(sArg) & """"
		End If
		nCount = nCount + 1
	Next
	objShell.Run sScriptFolder & "Everything.exe -p " & sArgs, 1, False
End Sub

Function GetFolder(sFolderArg)
	If Not (objFSO.FolderExists(sFolderArg)) Then WScript.Echo "Invalid folder: " & sFolderArg & WScript.Quit 
	GetFolder = sFolderArg
End Function

Set objFSO		= Nothing
Set objShell	= Nothing
Last edited by MandraK on Mon May 17, 2021 9:08 am, edited 2 times in total.

therube
Posts: 3423
Joined: Thu Sep 03, 2009 6:48 pm

Re: Multiple folder search from Windows context menu

Post by therube » Mon Jan 06, 2020 6:22 pm

If you use -s instead of -path & enclose the (multiple) paths in only 1 set of quotes, does that work?

-s "path1|path2|path3"

MandraK
Posts: 10
Joined: Mon Jan 06, 2020 4:45 pm

Re: Multiple folder search from Windows context menu

Post by MandraK » Mon Jan 06, 2020 6:54 pm

therube wrote:
Mon Jan 06, 2020 6:22 pm
If you use -s instead of -path & enclose the (multiple) paths in only 1 set of quotes, does that work?

-s "path1|path2|path3"
Thank you for your response..

It does work with the -s argument unless there's a space on the path for any given folder..
Then an "invalid path" error happens.

All double quotes get stripped using the -s argument, even the first and last ones.

NotNull
Posts: 3653
Joined: Wed May 24, 2017 9:22 pm

Re: Multiple folder search from Windows context menu

Post by NotNull » Mon Jan 06, 2020 8:09 pm

If you end up with this commandline:

Code: Select all

Everything.exe -search " """c:\first path\""" | """c:\second path\""" "
You will get this search query inside Everything:

Code: Select all

 "c:\first path\" | "c:\second path\"
And that is the correct syntax to search in multiple paths (including spaces).

MandraK
Posts: 10
Joined: Mon Jan 06, 2020 4:45 pm

Re: Solved !!

Post by MandraK » Mon Jan 06, 2020 8:32 pm

NotNull wrote:
Mon Jan 06, 2020 8:09 pm
If you end up with this commandline:

Code: Select all

Everything.exe -search " """c:\first path\""" | """c:\second path\""" "
You will get this search query inside Everything:

Code: Select all

 "c:\first path\" | "c:\second path\"
And that is the correct syntax to search in multiple paths (including spaces).
Yep! that's it.. thank you.. :)

This worked for me:

Code: Select all

For Each sArg In arrArgs
	If nCount > 1 Then
		Args = sArgs & "|""""""" & GetFolder(sArg) & """"""""
	Else
		sArgs = """""""" & GetFolder(sArg) & """"""""
	End If
	nCount = nCount + 1
Next
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & """", 1, True

NotNull
Posts: 3653
Joined: Wed May 24, 2017 9:22 pm

Re: Multiple folder search from Windows context menu

Post by NotNull » Mon Jan 06, 2020 8:58 pm

:thumbsup:

Please post the context-menu registry entries too.
I suspect more people will be interested in this :)

MandraK
Posts: 10
Joined: Mon Jan 06, 2020 4:45 pm

Re: Multiple folder search from Windows context menu

Post by MandraK » Tue Jan 07, 2020 12:32 am

NotNull wrote:
Mon Jan 06, 2020 8:58 pm
:thumbsup:

Please post the context-menu registry entries too.
I suspect more people will be interested in this :)
Ok!, for anyone interested..

Important: If we select two or more folders in file explorer and try to run any program (like everything.exe) from the context menu, Windows will run the command each time for each folder, instead of one command with several folders as parameters. So you'll get multiple instances of everything.exe, one for each folder, instead of a single instance searching multiple folders as we want it. So we need a tool to wrap around this issue. There are several ways to do it (like a COM object, a script, or a standalone program), but I'll just mention an existing utility called singleinstance.exe that's available on GitHub..

Step 1: Download singleinstance.exe and save it to Everything's folder (or other path if you intend to use it for sth else):
https://github.com/zenden2k/context-men ... ses/latest

Step 2: Copy the following VBScript and save it to Everything's folder (EVContext.vbs):

Code: Select all

'+============================================
'|  EVContextSearch
'|  Date	 2020-01-01 18:57
'|  Last	 2020-04-13 04:11
'|  Author	 Melvin D. Nava <mdnava[at]gmail.com>
'|  URL		 https://www.mdnava.com/
'+============================================
'|	Search multiple folders from the Windows context menu.
'|	If filenames are given, then paths are stripped and only names are searched.
'|	
'|	Note: Folders as argument are separated by | (everything.exe -p "path1"|"path2"|"path3")
'|		  Program interface searches multiple paths.. But from the command line it strips double quotes
'|		  from each given path, so it breaks when there are spaces on any of them.
'|		  Workaround from: https://www.voidtools.com/forum/viewtopic.php?f=5&t=8697
'|			$ Everything.exe -search " """c:\first path\""" | """c:\second path\""" "
'|	Args: <folders_to_search>
'+============
Option Explicit
If WScript.Arguments.Count < 1 Then MsgBox "Missing parameter, nothing to do!.", vbInformation, "Notice" & WScript.Quit()
Dim arrArgs, objFSO, objShell
Set arrArgs		= Wscript.Arguments
Set objFSO		= CreateObject("Scripting.FileSystemObject")
Set objShell	= CreateObject("WScript.Shell")
EVContextSearch()

' ===========================
' == Main Subroutine ========
' ===========================
Public Sub EVContextSearch()
	Dim sScriptFolder, sArg, sArgs, nCount
	Dim objFile
	sScriptFolder = objFSO.GetParentFolderName(objFSO.GetFile(Wscript.ScriptFullName)) & "\"
	nCount = 1

	For Each sArg In arrArgs
		If (objFSO.FileExists(sArg)) Then		'** Case for files (search base name only)
			Set objFile	= objFSO.GetFile(GetFile(sArg))
			sArg		= objFSO.GetBaseName(objFile)
		ElseIf (objFSO.FolderExists(sArg)) Then	'** Case for folders
			sArg		= GetFolder(sArg)
		Else									'** Case for any other string
			sArg		= Trim(sArg)
		End If

		If nCount > 1 And sArg <> "" Then	'** Join arguments with |
			sArgs = sArgs & "|""""""" & sArg & """"""""
		ElseIf  sArg <> "" Then
			sArgs = """""""" & sArg & """"""""
		End If
		nCount = nCount + 1
	Next

	objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False
End Sub

' ===========================
' == Return file path =======
' ===========================
Function GetFile(sFileArg)
	If Not (objFSO.FileExists(sFileArg)) Then WScript.Echo "Invalid file: " & sFileArg & WScript.Quit 
	GetFile = sFileArg
End Function

' ===========================
' == Return folder path =====
' ===========================
Function GetFolder(sFolderArg)
	If Not (objFSO.FolderExists(sFolderArg)) Then WScript.Echo "Invalid folder: " & sFolderArg & WScript.Quit 
	GetFolder = sFolderArg
End Function

Set objFSO		= Nothing
Set objShell	= Nothing
Step 3: Copy the following code into a .reg file (like EVInstall.reg), modify it with the correct PATHs (6 of them), and run it..

Code: Select all

Windows Registry Editor Version 5.00

; Add to context menus (FOLDERS)
[HKEY_CLASSES_ROOT\Directory\shell\AB.Everything]
@="Search with Everything"
"Icon"="\"D:\\Progs\\Utilities\\Everything\\Everything.exe\",0"
[HKEY_CLASSES_ROOT\Directory\shell\AB.Everything\command]
@="D:\\Progs\\Utilities\\Everything\\singleinstance.exe \"%V\" \"D:\\Progs\\Utilities\\Everything\\EVContext.vbs\" $files --si-timeout 400"

; Add to context menus (FOLDER BACKGROUND)
[HKEY_CLASSES_ROOT\Directory\Background\shell\AB.Everything]
@="Search with Everything"
"Icon"="\"D:\\Progs\\Utilities\\Everything\\Everything.exe\",0"
[HKEY_CLASSES_ROOT\Directory\Background\shell\AB.Everything\command]
@="D:\\Progs\\Utilities\\Everything\\singleinstance.exe \"%V\" \"D:\\Progs\\Utilities\\Everything\\EVContext.vbs\" $files --si-timeout 400"

Hope this helps..
Last edited by MandraK on Mon May 17, 2021 9:19 am, edited 4 times in total.

NotNull
Posts: 3653
Joined: Wed May 24, 2017 9:22 pm

Re: Multiple folder search from Windows context menu

Post by NotNull » Tue Jan 07, 2020 8:31 pm

Thanks a lot for posting!

A long time ago I was writing my own version of singleinstance.exe (in batch!). Things got ugly and above all: not working.
Never came to my mind to search the Internet for this. Singleinstance.exe is going to help me in the future for sure! (I mess around with (static) context menu verbs quite often too :-))

Thanks again!

amsgh12
Posts: 3
Joined: Mon Jan 10, 2022 12:55 am

Re: Multiple folder search from Windows context menu

Post by amsgh12 » Mon Jan 10, 2022 1:01 am

Ive followed the directions but im getting the below error
Image


My everything folder "C:\Program Files\Everything 1.5a\Everything64.exe"

Its line 53 which is below. Im using everything64 so i think thats the issue. I tried changing the below name but it still didnt work. Do i have to specify the full path in line 53?
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False

amsgh12
Posts: 3
Joined: Mon Jan 10, 2022 12:55 am

Re: Multiple folder search from Windows context menu

Post by amsgh12 » Mon Jan 10, 2022 1:03 am


MandraK
Posts: 10
Joined: Mon Jan 06, 2020 4:45 pm

Re: Multiple folder search from Windows context menu

Post by MandraK » Mon Jan 10, 2022 4:51 pm

amsgh12 wrote:
Mon Jan 10, 2022 1:01 am
Its line 53 which is below. Im using everything64 so i think thats the issue. I tried changing the below name but it still didnt work. Do i have to specify the full path in line 53?
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False
As you mentioned, the script can't find (or access) the EVERYTHING binary. Either the path is wrong, or is possible the script doesn't have enough credentials. You could try a using path outside Program Files, which is usually restricted. Everything can work in portable mode, so you could just copy it to a different folder (like in "Documents") to try it out.

To be sure, try this code just before the line with the error:

Code: Select all

WScript.Echo sScriptFolder & "Everything.exe"
WScript.Quit
And make sure is the correct path and exists.. If it does exist, is most likely a permission thing.

Oh.. And is important that the script be located in the same folder as <everything.exe>, otherwise you should replace <sScriptFolder & "Everything.exe> with the actual full path to the binary.

NotNull
Posts: 3653
Joined: Wed May 24, 2017 9:22 pm

Re: Multiple folder search from Windows context menu

Post by NotNull » Mon Jan 10, 2022 5:14 pm

amsgh12 wrote:
Mon Jan 10, 2022 1:01 am
My everything folder "C:\Program Files\Everything 1.5a\Everything64.exe"

Its line 53 which is below. Im using everything64 so i think thats the issue. I tried changing the below name but it still didnt work. Do i have to specify the full path in line 53?
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False
On line 53, you can replace Everything.exe with Everything64.exe


(The script will "calculate" the full path itself (= the folder where you put this script, which should also be the folder where Everything is installed. In your case "C:\Program Files\Everything 1.5a".)

horst.epp
Posts: 726
Joined: Fri Apr 04, 2014 3:24 pm

Re: Multiple folder search from Windows context menu

Post by horst.epp » Mon Jan 10, 2022 5:17 pm

amsgh12 wrote:
Mon Jan 10, 2022 1:01 am
Ive followed the directions but im getting the below error
Image


My everything folder "C:\Program Files\Everything 1.5a\Everything64.exe"

Its line 53 which is below. Im using everything64 so i think thats the issue. I tried changing the below name but it still didnt work. Do i have to specify the full path in line 53?
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False
Of course you have to enter the full path to Everything64.exe in your case.

NotNull
Posts: 3653
Joined: Wed May 24, 2017 9:22 pm

Re: Multiple folder search from Windows context menu

Post by NotNull » Mon Jan 10, 2022 6:24 pm

horst.epp wrote:
Mon Jan 10, 2022 5:17 pm
Of course you have to enter the full path to Everything64.exe in your case.
The full path comes from sScriptFolder, which was defined previously in the script:

Code: Select all

sScriptFolder = objFSO.GetParentFolderName(objFSO.GetFile(Wscript.ScriptFullName)) & "\"
Subtitled:
sScriptFolder = the folder where the script is installed, followed by a "\".
And as the script should be installed in the Everything programfolder, it is equal to that folder (+ "\") : "C:\Program Files\Everything 1.5a\"

So there is no need to specify the full path explicitly. But if you want, you can:
MandraK wrote:
Mon Jan 10, 2022 4:51 pm
Oh.. And is important that the script be located in the same folder as <everything.exe>, otherwise you should replace <sScriptFolder & "Everything.exe> with the actual full path to the binary.

amsgh12
Posts: 3
Joined: Mon Jan 10, 2022 12:55 am

Re: Multiple folder search from Windows context menu

Post by amsgh12 » Mon Jan 17, 2022 12:30 am

MandraK wrote:
Mon Jan 10, 2022 4:51 pm
amsgh12 wrote:
Mon Jan 10, 2022 1:01 am
Its line 53 which is below. Im using everything64 so i think thats the issue. I tried changing the below name but it still didnt work. Do i have to specify the full path in line 53?
objShell.Run sScriptFolder & "Everything.exe -s """ & sArgs & " """, 1, False
As you mentioned, the script can't find (or access) the EVERYTHING binary. Either the path is wrong, or is possible the script doesn't have enough credentials. You could try a using path outside Program Files, which is usually restricted. Everything can work in portable mode, so you could just copy it to a different folder (like in "Documents") to try it out.

To be sure, try this code just before the line with the error:

Code: Select all

WScript.Echo sScriptFolder & "Everything.exe"
WScript.Quit
And make sure is the correct path and exists.. If it does exist, is most likely a permission thing.

Oh.. And is important that the script be located in the same folder as <everything.exe>, otherwise you should replace <sScriptFolder & "Everything.exe> with the actual full path to the binary.
Thank you very much it was in fact permissions. I moved all the folders and files into my e drive. Changed paths and now it works. Thanks again!

Post Reply