Select files with same name pattern as selected

Features wanted...
Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

For some reasons, ListPane() doesn't select files when the wildcard pattern (2nd arg) contains brackets ('[' and ']'), even if backslash-escaped.

Eg.

Code: Select all

$base = 'ok [joe].part';
$list = ListPane('a', "$base*", 5);
while active pane contains files like "ok [joe].part1.rar", "ok [joe].part2.rar" etc.

Bug/feature?

admin
Site Admin
Posts: 60585
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Select files with same name pattern as selected

Post by admin »

Feature! "[joe]" is a special pattern group syntax and means "any letter j, o, e". To pass "[joe]" literally you have to escape the first bracket like this: "[[]joe]".

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Ok; the 2nd argument is referred to as a "wildcard pattern" in the doc, with (*, ?) being the wildcards, so this regexp-ish bracket feature is undocumented (no big deal, just pointing it out).
Unless I messed up somewhere, the brackets can't be escaped with backslashes, so this makes it a bit awkward for file names containing brackets.

I quick-fixed the script this way:

Code: Select all

    $patbase = RegexReplace("$base", '([][])', '[$1]');
    $list = ListPane('a', "$patbase*", 5);
Also, the $regexEscape var should read:

Code: Select all

    $regexEscape = '([\[\]\\\^\$\.\|\?\*\+\(\)\{\}])';
(a closing bracket was missing).

admin
Site Admin
Posts: 60585
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Select files with same name pattern as selected

Post by admin »

Next version will have a flag that does it automatically for you.

Next version: Examples for Character Lists and flag NoCharacterLists (16):

Code: Select all

//list all items that contain "a" or "b" in the name:
inputselect("Test", listpane(, "[ab]"));
//list all items that contain "[ab]" in the name:
inputselect("Test", listpane(, "[ab]", 16));

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

FYI, '#' also has an undocumented special meaning, so the code should read:

Code: Select all

    $patbase = RegexReplace("$base", '([]#[])', '[$1]');
    $list = ListPane('a', "$patbase*", 5);

Post Reply