Second request for help: globbing on a block of filenames
[1/8] from: princepawn:lycos at: 7-Sep-2000 8:17
I have a block which contains filenames. I would like to get a true or false value back
indicating whether or not there is a filename in the block that terminates with a r~
extension.
Please show me how to do this.
>> a
== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r %lconfig.r~
%nntp.r %notes.html %rebdoc.r
%rebol.exe %re...
Could someone show me how to glob for feedback.r?
In other words, I want to say
[2/8] from: johnkenyon:ibm at: 7-Sep-2000 8:45
Hi,
Try -
test-for-ext: func [
"Search a block for items ending with the given string. Returns TRUE or
FALSE"
value [string!]
data [block!]
] [
foreach item data [
if find/reverse tail item value [ return true ]
false
]
]
cheers, john
I have a block which contains filenames. I would like to get a true or
false value back indicating whether or not there is a filename in the block
that terminates with a r~ extension.
Please show me how to do this.
>> a
== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r
%lconfig.r~ %nntp.r %notes.html %rebdoc.r
%rebol.exe %re...
Could someone show me how to glob for feedback.r?
In other words, I want to say
[3/8] from: johnkenyon:ibm at: 7-Sep-2000 8:47
Hi,
Or even -
test-for-ext: func [
"Search a block for items ending with the given string. Returns TRUE or
FALSE"
value [string!]
data [block!]
] [
foreach item data [
if find/last item value [ return true ]
false
]
]
cheers, john
I have a block which contains filenames. I would like to get a true or
false value back indicating whether or not there is a filename in the block
that terminates with a r~ extension.
Please show me how to do this.
>> a
== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r
%lconfig.r~ %nntp.r %notes.html %rebdoc.r
%rebol.exe %re...
Could someone show me how to glob for feedback.r?
In other words, I want to say
[4/8] from: christmn:clackamas:ds:adp at: 7-Sep-2000 10:29
This is a multi-part message in MIME format.
------=_NextPart_000_0025_01C018B6.8A0BAF70
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
a: [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r %lconfig.r~
%nntp.r %notes.html %rebdoc.r %rebol.exe]
foreach file a [if find/match/any file "*.r~" [print ["found one: " :file]]]
OR
a: [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r %lconfig.r~
%nntp.r %notes.html %rebdoc.r %rebol.exe]
pattern: "*.r~"
foreach file a [if find/match/any file pattern [print ["found one: " :file]]]
OR for looking directly at the systems directories
files: read %.
pattern: "*.cgi"
foreach file files [if find/match/any file pattern [print ["found one: " :file]]]
found one: demo.cgi
found one: printenv.cgi
found one: webenv.cgi
found one: test.cgi
found one: man.cgi
found one: fetchurl.cgi
found one: hw2test.cgi
found one: wx.cgi
found one: reb_fetch.cgi
found one: fxhtml.cgi
----- Original Message -----
From: [princepawn--lycos--com]
To: [list--rebol--com]
Sent: Thursday, September 07, 2000 8:17 AM
Subject: [REBOL] Second request for help: globbing on a block of filenames
I have a block which contains filenames. I would like to get a true or false value back
indicating whether or not there is a filename in the block that terminates with a r~
extension.
Please show me how to do this.
>> a
== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~ %lconfig.r %lconfig.r~
%nntp.r %notes.html %rebdoc.r
%rebol.exe %re...
Could someone show me how to glob for feedback.r?
In other words, I want to say
Get your FREE Email and Voicemail at Lycos Communications at
http://comm.lycos.com
------=_NextPart_000_0025_01C018B6.8A0BAF70
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4134.600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>a: [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r
%instinet.r~ %lconfig.r %lconfig.r~ %nntp.r %notes.html %rebdoc.r
%rebol.exe]<BR>foreach file a [if find/match/any file "*.r~" [print ["found one:
:file]]]</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>OR</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>a: [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r
%instinet.r~ %lconfig.r %lconfig.r~ %nntp.r %notes.html %rebdoc.r
%rebol.exe]<BR>pattern:
*.r~"<BR>foreach file a [if find/match/any file pattern
[print ["found one: " :file]]]</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>OR for looking directly at the systems
directories</FONT></DIV>
<DIV><FONT size=2><BR><FONT size=2>
<P>files: read %.<BR><FONT size=2>pattern: "*.cgi"<BR>foreach file files [if
find/match/any file pattern [print ["found one: " :file]]]<BR></FONT><FONT
size=2><BR>found one: demo.cgi<BR>found one: printenv.cgi<BR>found one:
webenv.cgi<BR>found one: test.cgi<BR>found one: man.cgi<BR>found one:
fetchurl.cgi<BR>found one: hw2test.cgi<BR>found one: wx.cgi<BR>found one:
reb_fetch.cgi<BR>found one: fxhtml.cgi</P></FONT></FONT></DIV></FONT>
<DIV><FONT size=2></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000
2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=[princepawn--lycos--com]
href="mailto:[princepawn--lycos--com]">[princepawn--lycos--com]</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=[list--rebol--com]
href="mailto:[list--rebol--com]">[list--rebol--com]</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, September 07, 2000 8:17
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [REBOL] Second request for help:
globbing on a block of filenames</DIV>
<DIV><BR></DIV>I have a block which contains filenames. I would like to get a
true or false value back indicating whether or not there is a filename in the
block that terminates with a r~ extension.<BR><BR>Please show me how to do
this.<BR><BR>>> a<BR>== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r
%instinet.r~ %lconfig.r %lconfig.r~ %nntp.r %notes.html
%rebdoc.r<BR>%rebol.exe %re...<BR><BR>Could someone show me how to glob for
feedback.r?<BR><BR>In other words, I want to say<BR><BR><BR>Get your FREE
Email and Voicemail at Lycos Communications at<BR><A
href="http://comm.lycos.com">http://comm.lycos.com</A><BR><BR></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0025_01C018B6.8A0BAF70--
[5/8] from: ssayer:acuson at: 7-Sep-2000 14:44
This one and the one before won't work as asked because they'll return
true for files with r~ anywhere in the name. Try this instead (off the top
of my head):
has-backup-file?: func [
{Returns true if any item in block ends with r~}
arg [block!]
][
forall arg [
if (result: find first arg "r~") [
if (length? result) = 2 [
return true
]
]
]
return false
]
On Thu, 7 Sep [2000johnkenyon--uk--ibm--com] wrote:
[6/8] from: ssayer:acuson at: 7-Sep-2000 14:53
Oops, it occurs to me that I forgot to add the tail refinement to my first
find (meaning a file feeder~fodder.r~ would be missed for example). This
should work better:
has-backup-file?: func [
{Returns true if any item in block ends with r~}
arg [block!]
][
forall arg [
if (result: find/tail first arg "r~") [
if (length? result) = 2 [
return true
]
]
]
return false
]
Later,
Stephen
On Thu, 7 Sep 2000, S. Sayer wrote:
[7/8] from: joel:neely:fedex at: 7-Sep-2000 11:40
One possible solution is:
>> stuff: [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~
[ %lconfig.r %lconfig.r~ %nntp.r %notes.html %rebdoc.r %dummy.ftp
[ %dummy2.ftp~ %readby.ftp]
== [%cast.r %feedback.r %ftp.r %ftp.r~ %instinet.r %instinet.r~
%lconfig.r %lconfig.r~ %nntp.r %notes.html %rebdoc.r %dummy.ft...
>> foreach thing stuff [
[ print [
[ thing "^-"
[ either parse/all thing [thru "r~"] ["pass"]["fail"]
[ ]
[ ]
cast.r fail
feedback.r fail
ftp.r fail
ftp.r~ pass
instinet.r fail
instinet.r~ pass
lconfig.r fail
lconfig.r~ pass
nntp.r fail
notes.html fail
rebdoc.r fail
dummy.ftp fail
dummy2.ftp~ fail
readby.ftp fail
>>
This depends on the fact that the parse only succeeds if it can find
r~
and, in doing so, arrive at the end of the string.
HTH,
-jn-
[princepawn--lycos--com] wrote:
[8/8] from: jkinraid:clear at: 9-Sep-2000 15:03
Hi,
> Oops, it occurs to me that I forgot to add the tail refinement to my first
> find (meaning a file feeder~fodder.r~ would be missed for example). This
<<quoted lines omitted: 14>>
> Later,
> Stephen
You could also use the empty? function if you wanted
has-backup-file?: func [
{Returns true if any item in block ends with r~}
arg [block!]
/local result
][
forall arg [
if all [
result: find/last/tail first arg "r~"
empty? result
][
return true
]
]
false
]
Julian Kinraid
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted