Search Preprocessor

Discussion related to "Everything" 1.5 Alpha.
Post Reply
void
Site Admin
Posts: 7142
Joined: Fri Oct 16, 2009 11:31 pm

Search Preprocessor

Post by void » Thu May 27, 2021 2:18 am

The Search Preprocessor rewrites your searches.
Searches passed from the command line are automatically expanded.
Searches are expanded when executing an Everything query.



Syntax

#function:arg1,arg2,arg3,...
#function:<arg1,arg2,arg3,...>
#<function:arg1,arg2,arg3,...#>:
#<:a literal block of text#>:
"an exact phrase"


The #function:<arg1,arg2,arg3,...> or #<function:arg1,arg2,arg3,...#>: syntax works best when you need to change text within other text.
For example:
abc#upper:<#clipboard:>123

Parsing a function terminates at a space or OR operator (|) unless you use one of the #function:<arg1,arg2,arg3,...> or #<function:arg1,arg2,arg3,...#>: syntax variants.
Use double quotes (") to escape spaces and |.

The follow syntax is also supported:
#(function:arg1,arg2,arg3,...#):
#[function:arg1,arg2,arg3,...#]:
#{function:arg1,arg2,arg3,...#}:
#(:a literal block of text#):
#[:a literal block of text#]:
#{:a literal block of text#}:



Examples

#clipboard:
#len:<abc> => 3
#eval:1<<17 => 131072
#pathpart:"c:\windows\system32" => c:\windows



Registry Examples

[HKEY_CLASSES_ROOT\*\shell\Find Dupes in Everything\command]
"C:\Program Files\Everything\Everything64.exe" -s size:#getproperty:<"%1","size">



Command Line Examples

Everything64.exe -s #[year:#now:#]:-#[text:#[month:#now:#]:,00#]:-#[text:#[day:#now:#]:,00#]:



Character Entities
#num:#
#quot:"
#lt:<
#gt:>
#comma:,
#colon::


Functions

If the search starts with /#function: and ENTER is pressed, the search will be replaced with the expanded preprocessor text.
For example, typing in the search /#len:abc and pressing ENTER will replace the search with 3.



#abs:<expression>
Return the absolute value of expression.
Example: #abs:<2-3> => 1



#add-trailing-path-separator:<filename>
Add a trailing path separator to the end of filename.
Does nothing if the filename already contains a trailing path separator.
The appended path separator character will depend on the filename.
Example: #add-trailing-path-separator:<c:> => c:\
Example: #add-trailing-path-separator:"C:\Program Files" => C:\Program Files\



#and:<expression1,expression2,expression3,...>
Returns the logical AND result of all expressions.
Returns 1 if all expressions are TRUE, 0 otherwise.
Example: #and:<#find:<my,my search>,#find:<search,my search>> => 1
Example: #and:1,1,0 => 0



#basename:<path>
#filename:<path>
Returns the basename from the full path and filename.
Example: #basename:<C:\Windows\explorer.exe> => explorer.exe
Example: #basename:"C:\Windows\Notepad.exe" => Notepad.exe



#char:<expression>
Return the character for the specified unicode code point.
Example: #char:65 => A
Example: #char:97 => a



#clipboard:
Returns the text content from the clipboard.
Can only be used from the main search window.
The search is dynamic, copying text will update your results in real-time.



#clean:<text>
Returns text with non-printable characters removed.
Example: #clean:?abc? => abc



#code:<character>
Returns the character code from the specified character.
Example: #code:A => 65



#concatenate:<text1,text2,text3,...>
#concat:<text1,text2,text3,...>
Concatenate all text.
Example: #concat:abc,123,foo,bar => abc123foobar



#day:<date>
Returns the day from date.
date can be in YYYY-MM-DD hh:mm:ss format or a filetime.
Example: #day:#now:



#dec2hex:<decimal-value>
Returns the hex value from the specified decimal value.
Example: #dec2hex:255 => FF



#define:<definition>
Defines the function or variable and returns an empty string.
If the function or variable is already defined, it is replaced with the new definition.
Syntax: name=value
Syntax: name<parameter list>=function-body
Example: #define:x=123
Example: #define:mysum<a,b>=#<:#eval:#a:+#b:#>:



#directory-exists:<filename>
Returns 1 if the specified filename is a directory on disk, 0 otherwise.
Can only be used from the main search window.
Example: #directory-exists:<C:\Windows> => 1
Example: #directory-exists:"C:\Windows\Notepad.exe" => 0



#element:<list,delimiter-characters,n>
Returns the nth element (1 based) from a delimited list.
Example: #element:<"Red;Green;Blue",;,#randbetween:<1,3>>



#elementcount:<list,delimiter-characters>
Returns the number of elements in a delimited list.
Example: #elementcount:<"Red;Green;Blue",;> => 3



#eval:<expression>
Evaluate expression and return the result.
Example: #eval:<1+1> == 2
Example: #eval:<3*(4+5)> == 27
Example: #eval:<1<<17> == 131072



#exact:<value1,value2>
Returns 1 if value1 is exactly the same as value2, 0 otherwise.
Example: #exact:abc,abc => 1
Example: #exact:abc,Abc => 0



#extension:<filename>
Return the extension from the specified filename, including the dot.
Example: #extension:<New Text Document.txt> => .txt
Example: #extension:<Everything.exe> => .exe



#file-exists:<filename>
Returns 1 if the specified filename is a file on disk, 0 otherwise.
Can only be used from the main search window.
Example: #directory-exists:<C:\Windows> => 0
Example: #directory-exists:"C:\Windows\Notepad.exe" => 1



#filetime:<date-time>
Returns the date-time as a filetime.
Example: #day:#eval:<#filetime:#now: + 360000000000> => (tomorrow's day)



#get-date-created:<filename>
Get the date created filetime from the specified filename.
Example: #get-date-created:<"C:\Windows\Notepad.exe">



#get-date-modified:<filename>
Get the date modified filetime from the specified filename.
Example: #get-date-modified:<"C:\Windows\Notepad.exe">



#getenv:<name>
Get the environment variable value from the specified name.
Can only be used from the main search window.
Example: #getenv:windir => C:\Windows
Example: #getenv:"ProgramFiles" => C:\Program Files



#get-long-path-name:<short-path>
Get the long path from the specified short path.
Can only be used from the main search window.
Example: #get-long-path-name:C:\Progra~1 => C:\Program Files



#get-property:<filename,property-canonical-name>
Get the specified property as a raw value from the specified filename.
Example: #get-property:<"C:\Windows\Notepad.exe",size> => (size of Notepad.exe in bytes)
Example: #get-property:<"C:\Windows\Notepad.exe",date-modified> => (Date Notepad.exe was last modified as a filetime)
Example: size:#get-property:<"C:\Windows\Notepad.exe",size>
Example: dm:#get-property:<"C:\Windows\Notepad.exe",date-modified>



#get-size:<filename>
Get the size of the file from the specified filename.
Example: #get-size:<"C:\Windows\Notepad.exe"> => (size of Notepad.exe in bytes)



#has-basename:<path>
#has-filename:<path>
Returns 1 if the specified path includes a basename, 0 otherwise.
Example: #has-basename:"C:\Windows\Notepad.exe" => 1
Example: #has-basename:"" => 0



#has-extension:<filename>
Returns 1 if the specified filename contains an extension, 0 otherwise.
Example: #has-extension:"C:\Windows\Notepad.exe" => 1
Example: #has-extension:"C:\Windows" => 0



#has-parent-path:<path>
Returns 1 if the specified path contains a parent, 0 otherwise.
Example: #has-parent-path:"C:\Windows\Notepad.exe" => 1
Example: #has-parent-path:"C:" => 0



#has-relative-path:<path>
Returns 1 if the length of the root of path is 0, 0 otherwise.
Example: #has-relative-path:"C:\Windows\Notepad.exe" => 1
Example: #has-relative-path:"C:" => 0


#has-root-directory:<path>
Returns 1 if the specified path is a root, 0 otherwise.
Example: #has-root-directory:"C:\Windows" => 1
Example: #has-root-directory:"Windows\Notepad.exe" => 0
See #root-directory:


#has-root-name:<path>
Returns 1 if the specified path is a root, 0 otherwise.
Example: #has-root-directory:"C:\Windows" => 1
Example: #has-root-directory:"Windows\Notepad.exe" => 0
See #root-name:



#has-root-path:<path>
Returns 1 if the length of the root of path is non-zero, 0 otherwise.
Example: #has-root-path:"C:\Windows" => 1
Example: #has-root-path:"Windows\Notepad.exe" => 0
See #root-path:


#has-stem:<path>
Returns 1 if the length of the stem from path is non-zero, 0 otherwise.
Example: #has-stem:"C:\Windows" => 1
Example: #has-stem:".exe" => 0
See #stem:



#hex2dec:<hex-value>
Returns the decimal value from the specified hex value.
Example: #hex2dec:ff => 255



#hour:<date-time>
Returns the hour from date-time.
Example: #hour:#now:


#if:<expression,value1,value2>
Returns value1 if the expression is non-zero, value2 otherwise.
Example: #if:<#eval:<#hour:#now: ">=" 12>,"Good afternoon","Good morning">



#ifs:<expression1,value1,expression2,value2,expression3,value3,...>
Returns value1 if the expression1 is non-zero. Otherwise,
Returns value2 if the expression2 is non-zero. Otherwise,
Returns value3 if the expression3 is non-zero.



#include:<filename>
Returns the text content from the file specified by filename.
Can only be used from the main search window.
Example: #include:"c:\searches\my search.txt



#find:<search,text,[start-index]>
#instr:<text,search,[start-index]>
Returns 0 if the search is not found.
Otherwise, returns the 1 based index of search in text.
Start the search from the optional start-index (1 if omitted).
Example: #find:<a,abc> => 1
Example: #find:<b,abc> => 2
Example: #find:<a,abc,2> => 0
Example: #find:<d,abc> => 0



#fixed:<number,number-of-places[,suppress_separator=0]>
Format a number with a specified number of decimal places.
Example: #fixed:<3.141592,3> => 3.141
Example: #fixed:<3141592,0,1> => 3141592
Example: #fixed:<3141592,0,0> => 3,141,592
Example: #fixed:<3141592,0> => 3,141,592


#is-absolute:<filename>
Returns the 1 if filename specifies an absolute path. Otherwise,
Returns 0 if filename specifies an relative path.
Example: #is-absolute:C:\Windows\Explorer.exe => 1
Example: #is-absolute:..\Explorer.exe => 0



#is-blank:<text>
Returns 1 if the specified text is empty, 0 otherwise.
Example: #is-blank:"abc" => 0
Example: #is-blank:"" => 1



#is-relative:<path>
Returns 1 if the specified path is a relative path, 0 otherwise.
Example: #is-relative:C:\Windows\Explorer.exe => 0
Example: #is-relative:..\Explorer.exe => 1


#left:<text,[n]>
Returns n (default=1) characters from the left of text.
Example: #left:<abc123,2> => ab



#len:<text>
Return the length of text in UTF-16 characters.
Example: #len:<abc> => 3
Example: #len:<"abc"> => 3
Example: #len:abc => 3



#lower:<text>
Convert text to lowercase.
Example: #lower:<ABC> => abc



#lpad:<text,count,character>
Left pad text to count characters with the specified character.
Example: #lpad:<abc,5,"*"> => **abc
Example: #lpad:<abc123,5,"*"> => abc123



#ltrim:<text,characters>
Remove the specified characters from the left of text.
Example: #ltrim:<" abc"," "> => abc



#makepreferred:<path>
Fixes root paths.
Example: #makepreferred:<c:> => C:\



#max:<expression1,expression2,expression3,...>
Return the max value from a list of expressions.
Example: #max:<1,10,100> => 100



#mid:<text,start-index,length>
#substr:<text,start-index,length>
#substring:<text,start-index,length>
Return the substring from text at start index (1 based) with the specified length.
Example: #substr:<abc123,2,4> => bc12



#min:<expression1,expression2,expression3,...>
Return the minimum value from a list of expressions.
Example: #min:<1,10,100> => 1



#minute:<date-time>
Returns the minute from date-time.
Example: #minute:#now:
Example: #text:<#minute:<#now:>,00>



#month:<date>
Returns the month from date.
Example: #month:#now:
Example: #text:<#month:<#now:>,00>



#not:<expression>
Return the logical NOT value of expression.
Example: #not:0 => 1
Example: #not:1 => 0
Example: #not:#len:abc => 0



#now:
Returns the current date-time in YYYY-MM-DD HH:mm:ss format.
The current date-time is gathered at the start of the query and does not change between calls.
Example: #text:<#hour:<#now:>,00>#text:<#minute:<#now:>,00>
Example: #filetime:#now: => (the current date-time as a filetime)



#or:<expression1,expression2,expression3,...>
Returns the logical OR result of all expressions.
Returns 1 if any expression is TRUE, 0 otherwise.
Example: #or:<0,0> => 0
Example: #or:<0,1> => 1
Example: #or:<1,0> => 1
Example: #or:<1,1> => 1



#path-canonicalize:<path>
Normalize the specified path.
Example: #pathcanonicalize:<C:\windows\..> == C:



#path-combine:<path1,path2>
Append path2 to path1 and return the result.
Includes a path separator if required.
Example: #path-combine:<"C:\Program Files","Everything"> => C:\Program Files\Everything
Example: #path-combine:<"C:\","Everything"> => C:\Everything



#path-exists:<path>
Returns 1 if the path is a file or folder on disk, 0 otherwise.
Can only be used from the main search window.
Example: #path-exists:<C:\Windows> => 1
Example: #path-exists:<C:\Windows\Explorer.exe> => 1



#path-part:<path>
Returns the parent path of the specified path.
Example: #path-part:<C:\Windows\Explorer.exe> => C:\Windows



#printf:<format,arg1,arg2,arg3,...>
Format text.
%d == number
%f == real number
%s == string
%c == character
%x == number as hex
%X == number as hex (with uppercase hex values)
%% == literal %
Example: #printf:<"%02d",1> => 01
Example: #printf:<"%d:%02d:%02d",21,4,9> => 21:04:09
Example: #printf:<"%d%%",99> => 99%
Example: #printf:<"%0.3f",3.141592> => 3.141
Example: #printf:<"%s%d",abc,123> => abc123
Example: #printf:<"0x%08x",65535> => 0x0000ffff
Example: #printf:<"%c",65> => A



#proper:<text>
Return the title case for text.
Example: #proper:<the LAZY fox> => The Lazy Fox



#quote:<text>
Returns quoted text for a search term.
Example: #quote:<abc 123> => "abc 123"



#rand:
Returns a pseudo random number.
Example: #eval:<#rand:%10>



#rand-between:<value1,value2>
Returns a random number between value1 and value2 (inclusive).
Example: #randbetween:<10,99>



#regex-escape:<text>
Returns text with special regex characters escaped.
Example: regex:#quote:#regex-escape:<C:\Program Files\Everything> => regex:"C:\\Program Files\\Everything"



#regex-extract:<text,search>
Returns text that matches the regular expression.
Example: #regex-extract:<abc123,\d\d\d> => 123



#regex-instr:<text,search,[start-index]>
Returns the 1-based index of the first match.
Example: #regex-instr:<abc123,[a-z]\d,2> => 3



#regex-match:<text,search>
Returns 1 if text matches the specified regular expression, 0 otherwise.
Example: #regex-match:<abc123,^a.*3$> => 1



#regex-replace:<text,search,new-text>
Replaces all matches of the specified regular expression in text with new-text.
Example: #regex-replace:<abc123,\d,x> => abcxxx



#relative-path:<path>
Return the relative path from the specified path.
Example: #relative-path:<C:\Program Files\Everything> => Program Files\Everything



#remove-basename:<path>
#remove-filename:<:path>
Remove the basename from the specified path.
Example: #remove-basename:<C:\Windows\Explorer.exe> => C:\Windows



#remove-extension:<filename>
Remove the extension from the specified filename.
Example: #remove-extension:<C:\Windows\Explorer.exe> => C:\Windows\Explorer
Example: #remove-extension:<Explorer.exe> => Explorer
Example: #remove-extension:<C:\Windows> => C:\Windows



#remove-trailing-path-separator:<path>
Remove any trailing path separator from path.
Example: #remove-trailing-path-separator:<C:\> => C:



#replace:<text,search,new-text>
#substitute:<text,search,new-text>
Replace all occurrences of search in text with new-text.
Example: #replace:<abc123,123,xxx> => abcxxx



#repeat:<text,n>
#rept:<text,n>
Return text repeated n times.
Example: #repeat:<ha,3> => hahaha



#replace-basename:<path,new-basename>
#replace-filename:<path,new-filename>
Replace the basename from path with the new-basename.
Example: #replace-basename:<C:\Windows\Explorer.exe,Notepad.exe> => C:\Windows\Notepad.exe



#replace-extension:<filename,new-extension>
Replace the extension in filename with the new-extension.
The new extension should include the dot.
Example: #replace-extension:<C:\Windows\Explorer.exe,.jpg> => C:\Windows\Explorer.jpg
Example: #replace-extension:<Notepad.exe,.png> => Notepad.png



#replace-terms:<terms,new-term-format>
Replace each term with new-term-format.
Use #term: to specify the current term.
Please escape #term: in the new-term-format argument so it is not prematurely expanded.
Example: #replace-terms:#<:abc 123 | foo bar#>:,#<:case:#term:#>: => case:abc case:123 | case:foo case:bar



#right:<text,[n]>
Return n characters from the right of text.
Example: #right:<abc123,2> => 23



#root-directory:<path>
Return the root name from the specified path.
Example: #root-directory:<C:\Windows\Explorer.exe> => \



#root-name:<path>
Return the root name from the specified path.
Example: #root-name:<C:\Windows\Explorer.exe> => C:



#root-path:<path>
Return the root path from the specified path.
Example: #root-path:<C:\Windows\Explorer.exe> => C:\



#rpad:<text,count,character>
Right pad text to count characters with the specified character.
Example: #rpad:<abc,5,"*"> => abc**
Example: #rpad:<abc123,5,"*"> => abc123



#today:
Returns the current date in YYYY-MM-DD format.
Example: #filetime:#today:


#rtrim:<text,characters>
Remove the specified characters from the right of text.
Example: #rtrim:<"abc "," "> => abc


#second:<date-time>
Returns the second from date-time.
Example: #second:#now:
Example: #text:<#second:<#now:>,00>



#stem:<filename>
Return the stem from the specified filename.
Example: #stem:<C:\Windows\Explorer.exe> => Explorer
Example: #stem:<Notepad.exe> => Notepad



#strcmp:<text1,text2>
Compare text1 with text2 and return the result.
Returns < 0 if text1 is less than text2, returns 0 if text1 and text2 are identical, returns > 0 if text1 is greater than text2.
Example: #strcmp:<abc,abc> => 0
Example: #strcmp:<A,B> => -1
Example: #strcmp:<abc,ABC> => 32



#stricmp:<text1,text2>
Case insensitive compare text1 with text2 and return the result.
Returns < 0 if text1 is less than text2, returns 0 if text1 and text2 are the same, returns > 0 if text1 is greater than text2.
Example: #stricmp:<abc,abc> => 0
Example: #stricmp:<abc,ABC> => 0
Example: #strcmp:<A,B> => -1


#stuff:<text,start-index,len,insert-text>
Insert insert-text into text at the specified start index.
The inserted text is repeated until the specified len is filled.
Example: #stuff:<abc123,2,2,xx> => abxx23
Example: #stuff:<Everything,1,5,No> => Nothing


#sum:<expression1,expression2,expression3,...>
Return the sum of all the specified expressions.
Example: #sum:<1,2,3> => 6



#switch:<expression,case1,value1,case2,value2,case3,value3,...,default-value>
Return value1 if case1 matches expression.
Return value2 if case2 matches expression.
Return default-value if no case matches the expression.
Example: #switch:<#weekday:<#now:>,0,"Sunday",1,"Monday",2,"Tuesday",3,"Wednesday",4,"Thursday",5,"Friday",6,"Saturday">



#term:
The current term in #replace-terms:
See #replace-terms:



#text:<value,format>
Format text.
YY/MM/DD = Date format. Example: 21/1/13
DDDD = Day of the week. Example: Monday
H:MM AM/PM = Time in 12 hour format. Example: 1:37 PM
000000 = Add leading zeros (0). Example: 000123
Example: #text:<2,000> => 002
Example: #text:<#now:,YYYY-MM-DD>



#textjoin:<delimiter,ignore-empty,text1,[text2,...]>
Join text with the specified delimiter and optionally ignore empty text.
Example: #textjoin:<";",1,Red,Green,,,Blue> => Red;Green;Blue
Example: #textjoin:<";",0,Red,Green,,,Blue> => Red;Green;;;Blue



#trim:<text,characters>
Remove the specified characters from the left and right of text.
Example: #trim:<" abc "," "> => abc



#unichar:<expression>
Return the character for the specified unicode code point.
Example: #unichar:0x1F44D => 👍
Example: #unichar:128077 => 👍



#unicode:<character>
Return the unicode code point for the specified character.
Example: #unicode:👍 => 128077



#upper:<text>
Return text as uppercase.
Example: #upper:abc => ABC



#version:
Return the Everything version as major.minor.revision.build.
Example: #version: => 1.5.0.1262



#weekday:<date>
Returns the week day from date.
0 = Sunday, 1 = Monday, ...
Example: #weekday:#now:



#xor:<expression1,expression2,expression3,...>
Returns the logical XOR result of all expressions.
Returns 1 if there is an odd number of non-zero expressions, 0 otherwise.
Example: #xor:<0,0> => 0
Example: #xor:<0,1> => 1
Example: #xor:<1,0> => 1
Example: #xor:<1,1> => 0



#year:<date>
Returns the year from date.
Example: #year:#now:



Dashes (-) in function names can be omitted.

Post Reply