It is currently March 28th, 2024, 7:03 pm

How do I use RegExpFilter with FolderInfo.dll?

Share and get help with Plugins and Addons
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

How do I use RegExpFilter with FolderInfo.dll?

Post by Virginityrocks »

[FileCount]
Measure=Plugin
Plugin=Plugins\FolderInfo.dll
Folder="C:\"
InfoType=FileCount
RegExpFilter="*Antelope*"

(Example) I'm trying to have FolderInfo.dll only count files containing the word "Antelope". How is this done? The example given doesn't work. I can't find a good explanation of RegExpFilter in the Rainmeter manual.
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How do I use RegExpFilter with FolderInfo.dll?

Post by jsmorley »

It is a regular expression, much like WebParser's RegExp or RegExpSubstitute / Substitute.

The difference is that instead of capturing things with (.*) to use in StringIndex or the \1\2 on the right hand side of Substitute pairs, you are simply creating a regular expression that will either be "true" or "false" (really "succeed" or "fail") for each file name.

The example in the manual might not be the best, since it might lead you to believe it has something to do with Windows / DOS "wildcards", but it doesn't. What the example is saying with regular expression is . any character, * zero or more times. Any file...

I'm not going to teach regular expression here, but what will work for you is:

RegExpFilter=(?i).*antelope.*
Any file that has zero or more * of any characters . followed by "antelope" followed by zero or more of any characters. This is basically "contains antelope".

the (?i) tells the entire expression to be "case insensitive", just like it does in:

RegExp=(?siU)<item>(.*)</item>

Case sensitivity can be important here, as while Windows is always case insensitive when dealing with file names, regular expression is not.

Other examples might be:

RegExpFilter=(?i).*antelope.*\.txt$
Any file that contains the string antelope in the file name and ends $ with an extension of ".txt"
Note that I "\escape" the . to use it as a literal dot and not the "any character" regular expression metacharacter.

RegExpFilter=(?i)^antelope.*
Any file that starts ^ with the string antelope in the name.

RegExpFilter=(?i).*antelope\.?.*$
Any file that ends $ with the string antelope in the name, with any extension (or no \.? extension).
The \.? in this case creates a "look back assertion". The effect is that it looks for \. (a dot) and then zero or more characters. If this fails, it stops, then goes back and looks for it without the dot, and zero or more characters. That causes it to succeed with or without an extension.

RegExpFilter=(?i).*\.[png|jpg|bmp]$
Any file, of any name, that ends in .png or .jpg or .bmp.

Extra credit:

RegExpFilter=(?i)(?=.*Morley)(?=.*Jeff)
Any file, that contains the string "Jeff" and the string "Morley" in any order.
IAmMorleyJeff.png
JeffMorleyAmI.png
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: How do I use RegExpFilter with FolderInfo.dll?

Post by Virginityrocks »

Very thorough practical explanation of RegExpFilter in Rainmeter! You should include this in the manual. :thumbup:
Droptop Four
Dropdown menu bar & app launcher for Windows & Rainmeter