Tips and Tricks #1 - Wildcards and filters

Chitchat about x² / 2X products

Moderators: fgagnon, nikos, Site Mods

Post Reply
User avatar
nikos
Site Admin
Site Admin
Posts: 15771
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

One of the sweetest things offered by 2xExplorer are these little things called wildcards (also known as filters, templates etc). Wildcards are shorthands for matching a range of strings or names. They are used all over the place in 2x, e.g. for selecting a subset of the files shown.

Wildcards are combinations of normal letters/numbers and two special characters, * and ?. The meaning of these two comes directly from the old command line (DOS) days:
* - matches zero or more characters
? - matches exactly one character

You can freely pick and mix these symbols in a wildcard, and have as many of them as you want. The simplest use is to match all the names with the same extension with a wildcard like *.txt. This means that we don't care about the base name (it can be "*", that is anything); we just need it to be followed by a dot '.' and the extension "txt", and that would be all if we wanted to select all the text files shown in a pane. Let's have a look at some more complicated examples:

a*.c?? - This will match any names beginning with 'a', and a three-letter extension beginning with a 'c'. Names like alpha.cxx, a.cpp and amen.cab will all be matched. On the other hand the following names won't be matched: beta.cpp (begins with 'b'), atest.c (doesn't have 3-letter extension), irrelevant.txt (has got no chance whatsoever :) )

?a*txt - This will match names whose second letter is 'a' and end-up in 'txt' (note that it doesn't have to be an extension since we didn't ask for a '.'). Here are a few matching names: ball.txt, aaa.dostxt, ratxt. And these won't match: atxt, aa.bak.

More complicated effects are achieved by combining two or more wildcards, separated by commas ','. For instance, if you want to see just the header and source files in your C++ project folder, just type in the address bar *.h, *.cpp .

If you want to obtain a PhD in wildcards, then you need to know about exclusion filters. These are combinations of two or more wildcards separated by commas as described above, but one or more of them are for exclusion, indicated by placing a minus '-' character in the beginning of the wildcard. So you could have oddities like *, -*.ncb, -*.aps which means "match all files except files with ncb or aps extensions".

Armed with this knowledge, you can now take better advantage of 2xExplorer features that use wildcards: (there is more than this)
<ul>
<li> Limit the files shown. Just type a wildcard in the address bar.
<li> Select or unselect files. To select only a few particular files out of those shown just type a wildcard in the Select/Unselect dialog (Mark menu). There are more options there to fine-tune what happens to the existing selection.
<li> Find command. A wildcard in the "Named" box will limit the number of files searched. This is especially useful if you are searching for contained text and you know e.g. the extension of the file.
</ul>

Successful graduates of this course won't have a problem solving a little puzzle, and figure out which of the following names match the wildcard ?a??*.*?xl, -*.txt, -*

bark.xl
bark.xxl
barking.myxl
aardvark.txt
man.opxl
ante.cpp
impossible.gzip

Is this a trick question or what? ;)
(no need to post answers to the forum!)
Post Reply