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
- 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*