[DONE] %ES_RESULTS%

Have a suggestion for "Everything"? Please post it here.
Post Reply
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

[DONE] %ES_RESULTS%

Post by NotNull »

Suggestion to have ES.exe set an environment variable with the number of matches it found (*) when (successfully) done.
(like ES_RESULTS=5 )

This would come in handy for some script I wrote a couple of months ago, but I even can't remember why (I worked around it anyway). So no urgency at all.


(*) Debatable what %ES_MATCHES% should be when the number of results is limited by the -n parameter.
Last edited by NotNull on Wed Oct 23, 2019 4:24 pm, edited 1 time in total.
void
Developer
Posts: 16698
Joined: Fri Oct 16, 2009 11:31 pm

Re: %ES_RESULTS%

Post by void »

How do other command line programs do this?

Would an option to return just the number of results be useful, for example:
ES foo bar -get-result-count

would output
23

if you had 23 files or folders matching foo bar

Then you do
for /f "tokens=*" %%a in (
'ES foo bar -get-result-count'
) do (
set es_ES_RESULTS=%%a
)

which would store the result count in %ES_RESULTS%
https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file

I could also add -get-folder-result-count / -get-file-result-count

Would using the returned error level be better? error level < 0 = error, otherwise the result count is returned.
therube
Posts: 4967
Joined: Thu Sep 03, 2009 6:48 pm

Re: %ES_RESULTS%

Post by therube »

Would using the returned error level be better? error level < 0 = error, otherwise the result count is returned.
I like that.

My (silly) first thought was a dotted error level.
So something like 1.256, where 1 was the error level & 256 was the number of results returned.
Then you'd only need to parse the .256 part to get the number of results.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: %ES_RESULTS%

Post by NotNull »

void wrote: Thu Jun 20, 2019 3:16 am How do other command line programs do this?
You are right; they can't!
CMD starts a child process ES.exe and ES can't change change the environment of it's parent.

It i possible with some CMD commands, but those turn out to be internal (= part of CMD.exe) and not external (.exe) as I assumed.

Would using the returned error level be better?
The error level used to be 8-bit (0..255), but maybe that has changed in modern Windows versions.
But still: redefining those return codes will cause too much side effects.
For example conditional commands. || and && look for errorlevel 0 / not 0 : ES.exe test && echo success / ES.exe test || echo error

EDIT: Just tested: Large return codes and negative ones are allowed on Win10.
Would an option to return just the number of results be useful, for example:
ES foo bar -get-result-count
Yes. please!

Checking can be shortened to: for /f %%a in ('ES.exe foo bar -get-result-count') do set ES_RESULTS=%%a
void
Developer
Posts: 16698
Joined: Fri Oct 16, 2009 11:31 pm

Re: %ES_RESULTS%

Post by void »

ES-1.1.0.12.zip
Usage:
ES.exe foo bar -get-result-count

Output:
23

getresultcount.bat example:
for /f "tokens=*" %%a in ('es foo bar -get-result-count') do (set ES_RESULTS=%%a)
echo %ES_RESULTS%

Notes:
The total result count is returned.
-n <count> is ignored
ES sets -n to 0 when using -get-result-count
This makes -get-result-count very fast if you do not specify a search to get the total number of indexed files and folders, for example:
ES.exe -get-result-count
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: %ES_RESULTS%

Post by NotNull »

Downloaded ... tested ... perfect!
And it is indeed blazingly fast. Thank you!


-get-result-count (and also -date-format ) are not yet mentioned on the Command Line Interface support page, so I can only award you a 9.5 for your work ;)
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: %ES_RESULTS%

Post by NotNull »

For the people using PowerShell:

Code: Select all

.\ES.exe -getresultcount | % {$ES_RESULTS = $_  -as [int]}
or

Code: Select all

$ES_RESULTS = (.\ES.exe -getresultcount).Toint32($null)
Powershell will see any output as text (string). With these commands the $ES_RESULTS variable will be converted to a 32-bit integer.


(Now you only have to be careful not to pass the 4 billion files limit :))
void
Developer
Posts: 16698
Joined: Fri Oct 16, 2009 11:31 pm

Re: %ES_RESULTS%

Post by void »

Added -get-result-count and -date-format to the support wiki, thanks.

https://www.voidtools.com/support/everything/command_line_interface/
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: %ES_RESULTS%

Post by NotNull »

There is something strange going on with -get-result-count.

If I add -sort date-run or -sort run-count as extra option to ES.exe, the result count is off.

Any idea what's going on?

Example:
TEST SCRIPT:

Code: Select all

@setlocal
@echo off
set ES=C:\TOOLS\EVERYTHING\ES.EXE
set QUERY=/ad  wfn:*system32*
rem set QUERY=/ad  wfn:*everything*


"%ES%" %QUERY%
echo on

"%ES%" %QUERY% -sort name -getresultcount
"%ES%" %QUERY% -sort path -getresultcount
"%ES%" %QUERY% -sort size -getresultcount
"%ES%" %QUERY% -sort extension -getresultcount
"%ES%" %QUERY% -sort date-created -getresultcount
"%ES%" %QUERY% -sort date-modified -getresultcount
"%ES%" %QUERY% -sort date-accessed -getresultcount
"%ES%" %QUERY% -sort attributes -getresultcount
"%ES%" %QUERY% -sort file-list-file-name -getresultcount
"%ES%" %QUERY% -sort run-count -getresultcount
"%ES%" %QUERY% -sort date-recently-changed -getresultcount
"%ES%" %QUERY% -sort date-run -getresultcount
RESULT:

Code: Select all

C:\Program Files\WindowsApps\Microsoft.LanguageExperiencePacknl-nl_17134.4.6.0_neutral__8wekyb3d8bbwe\Windows\System32
C:\Windows\System32

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort name -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort path -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort size -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort extension -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort date-created -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort date-modified -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort date-accessed -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort attributes -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort file-list-file-name -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort run-count -getresultcount
1

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort date-recently-changed -getresultcount
2

C:\temp>"C:\TOOLS\EVERYTHING\ES.EXE" /ad -n 20  wfn:*system32* -sort date-run -getresultcount
1

void
Developer
Posts: 16698
Joined: Fri Oct 16, 2009 11:31 pm

Re: %ES_RESULTS%

Post by void »

Thanks for the bug report.

The issue occurs when sorting by a "Special sort"
Everything consider a sort "special" when sorted by Recent change, Run Count or Date run.

When sorting by a special sort, items with a special sort property (eg: Run Count) are excluded from the total item count returned from the IPC query.

I've fixed the issue for Everything 1.4.1.947.
This fix will return the correct number of items for special sorts.
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: %ES_RESULTS%

Post by NotNull »

Thanks for explaining!

Briefly tested the new version 947 : all OK.
Thank you!
Post Reply