How to parse a filename using wildcards
[1/9] from: ale870::gmail at: 17-Jul-2007 8:04
Hello,
I have a problem using FIND/ANY with wildcards.
The problem is I need to find some files/dir using typical wildcards (or
something similar :-) ) to filter a filename list.
I tried to use FIND/MATCH/ANY, but I found a... bug (?).
Please take a look the following code:
foreach i read %/f/mydocs/rebol/. [
f1: (find/match/any i "view*.htm")
if f1 <> none [print f1 ]
]
using the syntax << find/match/any filename "view*.htm" >> the command will
return (for example):
introduction.htm
tutorial1.htm
information.html <----- WRONG!
information.html
is not correct! Since I didn't ask << find/match/any
filename "view*.htm*" >> (see the last asterisk).
Furthermore, if I use << find/match/any filename "view*.h" >> I got the
same results!!! :-(
I think the pattern matching is not perfect.
Can you suggest me a workaround (maybe using parse? In which way?) to make a
true, fully functional filter for filename, extension?
Thank you for your help!
--
--Alessandro
[2/9] from: santilli:gabriele:gm:ail at: 17-Jul-2007 8:28
2007/7/17, Alessandro Manotti <ale870-gmail.com>:
> I tried to use FIND/MATCH/ANY, but I found a... bug (?).
Not a bug - FIND returns the end of the match. You can use TAIL? to
check if the whole string matched.
>> find/match/any "something" "some*g"
== ""
>> find/match/any "somethingelse" "some*g"
== "else"
>> tail? find/match/any "something" "some*g"
== true
>> tail? find/match/any "somethingelse" "some*g"
== false
HTH,
Gabriele.
[3/9] from: ale870:gm:ail at: 17-Jul-2007 8:53
Great! It works!
Final draft code (to filter a directory), is the following:
foreach i read %/f/mydocs/rebol/. [
f1: (find/match/any i "view*.htm*")
if f1 <> none [
if tail? f1 [
print i
];if
];if
];foreach
Have you any suggestion how to optimize, but maintaining the code readable?
Thank you!
On 7/17/07, Gabriele Santilli <santilli.gabriele-gmail.com> wrote:
> 2007/7/17, Alessandro Manotti <ale870-gmail.com>:
> > I tried to use FIND/MATCH/ANY, but I found a... bug (?).
<<quoted lines omitted: 13>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
--Alessandro
[4/9] from: sqlab:gmx at: 17-Jul-2007 8:57
or shorter
>> find/match/any/tail "somethingelse" "some*g"
== none
>> find/match/any/tail "something" "some*g"
== "something"
>>
Gabriele Santilli wrote:
[5/9] from: ale870:gm:ail at: 17-Jul-2007 9:41
Wow!
This refiniment will compact my code something more:
foreach i read %/f/mydocs/rebol/. [
if (find/match/any/tail i "*.jpg") <> none [
print i
];if
];foreach
Thank you! I will publish it in my blog as tips & tricks.
On 7/17/07, sqlab <sqlab-gmx.net> wrote:
> or shorter
> >> find/match/any/tail "somethingelse" "some*g"
<<quoted lines omitted: 35>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
--Alessandro
[6/9] from: sqlab:gmx at: 17-Jul-2007 10:08
Hi Alessandro
There is no need for the parenthesis and the double comparison
just
if find/match/any/tail i "*.jpg" [
is enough
Alessandro Manotti wrote:
[7/9] from: ale870::gmail::com at: 17-Jul-2007 10:58
Oh yes, I know.
I used parenthesis just to make the code a little bit more readable even for
non expert people :-)
Regarding "none", you agree, I will eliminate it!
On 7/17/07, sqlab <sqlab-gmx.net> wrote:
> Hi Alessandro
> There is no need for the parenthesis and the double comparison
<<quoted lines omitted: 85>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
--Alessandro
[8/9] from: gregg:pointillistic at: 17-Jul-2007 9:35
Hi Alessandro,
AM> The problem is I need to find some files/dir using typical
AM> wildcards (or something similar :-) ) to filter a filename list.
...
AM> Can you suggest me a workaround (maybe using parse? In which way?)
AM> to make a true, fully functional filter for filename, extension?
I put %file-list.r on REBOL.org some time back. It's large, because it
does more than name matching, providing a dialect for filtering files
by name, date, size, and attributes. e.g.:
[%*.txt changed after 1-Aug-1998 < 10 kb not read-only]
-- Gregg
[9/9] from: ale870::gmail::com at: 17-Jul-2007 18:36
Wonderful!
I will check it immediately, since it could be very useful for two
applications I'm creating!
Thank you!
On 7/17/07, Gregg Irwin <gregg-pointillistic.com> wrote:
> Hi Alessandro,
> AM> The problem is I need to find some files/dir using typical
<<quoted lines omitted: 10>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
--Alessandro
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted