ES.exe, -no-result-error

General discussion related to "Everything".
Post Reply
therube
Posts: 4955
Joined: Thu Sep 03, 2009 6:48 pm

ES.exe, -no-result-error

Post by therube »

ES.exe, -no-result-error

Wanting a batch file that searches the current directory tree, with Everything (hopefully), & if Everything is not available, falls back to a DIR search.

Over time, I started with DIR, then substituted Everything.
Is there a more efficient method then in my latest iteration (last, below) of SF.BAT?

Is there a exit code that says, at least 1 result was returned?
If so I could simply check that & skip over the 'NEQ 0' (immediately below [instead of the last version, bottom]).

SS.BAT:

Code: Select all

@es.ex2 -pause -sort name -highlight -path . %1 %2 %3 -instance 15 -no-result-error

@if %errorlevel% NEQ 0 @cmd /c @dir /a /b /p /o:n /s *%1* %2 %3
run ES.exe
- UNLESS "ES" (aka, Everything.exe) is not running,
in which case (the ES would fail &) DIR is run (instead)

That part is fine, if Everything is not running, ES cannot return results, so I
then simply do a DIR. All of that is good.

Likewise, if I search an unindexed drive (say a flash drive I throw in), even
if Everything is running, ES will fail (as nothing on said unindexed drive is
seen), so then, the -no-result-error kicks in, & DIR fires, so I will then
find results on this unindexed drive. That too is good, just what I want.

Unintended consequence, is that if Everything is running & ES is run on an
indexed drive & no results are found, then that lack of results will then
(also) fire off the DIR - which is not wanted, is unnecessary.

Are there other error levels? Other error levels that may say, "drive not
indexed", such that:

> es.exe -drive-not-indexed, then DIR %1 ...

or can i check for the drive letter first & then check against indexed
drive letters, & if not found, then run DIR instead of ES ?

(IOW, how to get the drive letter of the current drive ?)


SS.BAT is run from intended drive, current directory too, so i'm not passing
any directory part to the (batch) program, only a file-name-part.

i could simply set up a different SS.BAT, but then i specifically need to
run 1 on particular drives & the other on other drives, kind of negating
the benefit...

Code: Select all

:: SS.BAT SjB 02-25-2024 .. 2001
:: Search Current Directory

@echo off

:: check for K: drive, a non-indexed (to Everything) drive

for %%i in (%cd%) do set VOLUME=%%~di
if %VOLUME%==K: (goto searchK:)


:: check for Everything not running [or if in Sandboxie] (in which case ES would not find anything, Error 8 or 9)

es.ex2 SS.BAT -instance 15 -no-result-error > nul
if %errorlevel% NEQ 0 goto searchK


:: if NOT K:, AND, Everything is running then) search CWD using Everything Search

es.ex2 -pause -sort name -highlight -path . %1 %2 %3 -instance 15
goto end:



:: search K: drive, using DIR

:searchK
@cmd /c @dir /a /b /p /o:n /s *%1* %2 %3

:end



:: \bin\old\SS_old.bat *%1*
NotNull
Posts: 5458
Joined: Wed May 24, 2017 9:22 pm

Re: ES.exe, -no-result-error

Post by NotNull »

From the documentation:
Return Codes

ES can return one of the following errorlevel codes:
Errorlevel Description
0 No known error, search successful.
1 Failed to register window class.
2 Failed to create listening window.
3 Out of memory.
4 Expected an additional command line option with the specified switch.
5 Failed to create export output file.
6 Unknown switch.
7 Failed to send Everything IPC a query.
8 Everything IPC window not found. Please make sure the Everything search client is running.

Most common is errorcode 8 (= %ERRORLEVEL% in CMD) : Everything not running, but with any ERRORLEVEL <> 0, something went wrong.
when ERRORLEVEL = 0, search went OK, even if no results were found.


BTW: no need to call CMD explicitly when running a batchfile (which is already run by CMD)

Untested:

Code: Select all

@echo off
es.ex2 -pause -sort name -highlight -path . %1 %2 %3 -instance 15 -no-result-error

If %errorlevel% NEQ 0 dir /a /b /p /o:n /s *%1* %2 %3
or shorter:

Code: Select all

@echo off
es.ex2 -pause -sort name -highlight -path . %1 %2 %3 -instance 15 || dir /a /b /p /o:n /s *%1* %2 %3
Don't know what the -no-result-error should do. Never used it and all my scripts got the ERRORLEVEL set to the right value anyway.
Post Reply