files out of order
[1/12] from: ryan:christiansen:intellisol at: 29-Mar-2001 13:33
I have a directory of XML-formatted messages, each saved with a numeric
filename based on the time of creation, for example
/news/20010329105032.txt
/news/20010329105033.txt
/news/20010329105034.txt
I use the following function to read the directory and to create a block of
file names, with the intention of placing the newest files first in the
block (in other words, the files with the highest number first in the
block.)
read-directory-messages: func [
"Read a directory of XML-formatted standard messages with the directory
determined by messageType."
message-directory [block!] "A block of file names corresponding to a
directory of XML-formatted standard messages."
][
message-block: copy []
foreach file-name message-directory [
file-contents: read file-name
insert message-block file-contents
]
]
But using the above function, I get files showing up in the block out of
order. Am I doing something wrong?
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
[2/12] from: gjones05:mail:orion at: 29-Mar-2001 14:07
From: <[ryan--christiansen--intellisol--com]>
> I have a directory of XML-formatted messages,
> each saved with a numeric
<<quoted lines omitted: 9>>
> read-directory-messages: func [
> "Read a directory of XML-formatted standard messages with the
directory
> determined by messageType."
> message-directory [block!] "A block of file names corresponding to a
<<quoted lines omitted: 9>>
> order. Am I doing something wrong?
> Ryan C. Christiansen
If I understand your intention correctly (which is a big assumption for me
on some days :-), then I would suggest reverse sorting the file names before
using the foreach block. For example, add this line before the foreach:
sort/reverse message-block
The file names should then be sorted largest first, therefore allowing the
foreach to iterate through the block in this order. Worth a try anyway.
Regards,
--Scott Jones
[3/12] from: ryan:christiansen:intellisol at: 29-Mar-2001 15:56
sort/reverse message-block
Did not work. Look at this page to see what I'm talking about. The messages
should be appearing based on time of creation, with the last created
message at the top of the list. Something is wrong.
http://www.fargonews.com/cgi-bin/messages.cgi?actionType=display&messageType=news&messageID=none
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
"GS Jones"
<[gjones05--mail]. To: <[rebol-list--rebol--com]>
orion.org> cc:
Sent by: Subject: [REBOL] Re: files out of order
[rebol-bounce--re]
bol.com
03/29/2001
02:07 PM
Please respond
to rebol-list
From: <[ryan--christiansen--intellisol--com]>
> I have a directory of XML-formatted messages,
> each saved with a numeric
<<quoted lines omitted: 9>>
> read-directory-messages: func [
> "Read a directory of XML-formatted standard messages with the
directory
> determined by messageType."
> message-directory [block!] "A block of file names corresponding to a
<<quoted lines omitted: 9>>
> order. Am I doing something wrong?
> Ryan C. Christiansen
If I understand your intention correctly (which is a big assumption for me
on some days :-), then I would suggest reverse sorting the file names
before
using the foreach block. For example, add this line before the foreach:
sort/reverse message-block
The file names should then be sorted largest first, therefore allowing the
foreach to iterate through the block in this order. Worth a try anyway.
Regards,
--Scott Jones
[4/12] from: ryanc:iesco-dms at: 29-Mar-2001 15:55
Use this before you pass the files to your read-directory-messages function:
sort-function: func [a b] [
a: info? a
b: info? b
a/date < b/date
]
sort/compare message-directory :sort-function
This function will only work if the files are referenced to the current working directory
(what-dir). Keep in mind the function passed to sort/compare can only take two arguments,
so use
inheritence to enhance it, such as with a path.
--Ryan Cole
[ryan--christiansen--intellisol--com] wrote:
> sort/reverse message-block
> Did not work. Look at this page to see what I'm talking about. The messages
<<quoted lines omitted: 77>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein
[5/12] from: brett:codeconscious at: 30-Mar-2001 12:36
> read-directory-messages: func [
> "Read a directory of XML-formatted standard messages with the
directory
> determined by messageType."
> message-directory [block!] "A block of file names corresponding to a
<<quoted lines omitted: 8>>
> But using the above function, I get files showing up in the block out of
> order. Am I doing something wrong?
I suspect all you need is to sort the message-directory block. Probably as
simply as adding the following line
sort message-directory
You'll get your messages in reverse order because you are inserting at the
head of the block each time.
Alternatively, after sorting do the foreach on the "head reverse" of the
message block and insert at the tail of your result.
Brett.
[6/12] from: bobr:dprc at: 30-Mar-2001 0:01
something to point out is that the files might not be in the directory
in name order to begin with. rebol is just returning the order the OS
returns them in.
many systems (unix in particular)
recycle directory entries so when you (or rebol executive)
uses the "opendir/readdir()" functions
the order you get them back in is a not-guaranteed-to-be-alphabetical
ordering. if nothing has done any renaming or deleting then this has a
/chance/
of being in creation order.
on linux, try "ls -U" to see this.
I see the solutions being offered go right for a sort so
you are on the right track.
At 01:33 PM 3/29/01 -0600, [ryan--christiansen--intellisol--com] wrote:
>I have a directory of XML-formatted messages, each saved with a numeric
>filename based on the time of creation, for example
<<quoted lines omitted: 39>>
>[rebol-request--rebol--com] with "unsubscribe" in the
>subject, without the quotes.
;# mailto: [bobr--dprc--net]
[7/12] from: arolls:bigpond:au at: 30-Mar-2001 16:55
Ryan, you actually want:
message-block: copy []
foreach file-name sort/reverse message-directory [
file-contents: read file-name
insert message-block file-contents
]
sorting the message-directory before use, not the message-block
with the contents of each file.
Anton.
[8/12] from: ryan:christiansen:intellisol at: 30-Mar-2001 8:54
Thanks, Anton. This is exactly what I needed to do.
-Ryan
------------------------------
Ryan, you actually want:
message-block: copy []
foreach file-name sort/reverse message-directory [
file-contents: read file-name
insert message-block file-contents
]
sorting the message-directory before use, not the message-block
with the contents of each file.
Anton.
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
[9/12] from: gjones05:mail:orion at: 30-Mar-2001 11:07
From: <[ryan--christiansen--intellisol--com]>
> Thanks, Anton. This is exactly what I needed to do.
> -Ryan
<<quoted lines omitted: 7>>
> sorting the message-directory before use, not the message-block
> with the contents of each file.
Is this any different than what I suggested yesterday? I agree with the
solution, I just don't understand why you found this version to work but not
mine. Just curious.
--Scott Jones
[10/12] from: ryan:christiansen:intellisol at: 30-Mar-2001 11:23
>> message-block: copy []
>> foreach file-name sort/reverse message-directory [
<<quoted lines omitted: 6>>
>Is this any different than what I suggested yesterday? I agree with the
>solution, I just don't understand why you found this version to work but
not
>mine. Just curious.
It does seem strange that
message-block: copy []
foreach file-name sort/reverse message-directory [
file-contents: read file-name
insert message-block file-contents
]
and
message-block: copy []
foreach file-name message-directory [
file-contents: read file-name
insert message-block file-contents
sort/reverse message-block
]
wouldn't accomplish the same thing. I'd like to know, too.
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
[11/12] from: ryanc::iesco-dms::com at: 30-Mar-2001 9:47
The functions submitted "work," but were designed to achieve different
outcomes. Scott's will sort the message according to contents, Anton's by
filename, and mine sorted by file date.
--Ryan
[ryan--christiansen--intellisol--com] wrote:
> >> message-block: copy []
> >> foreach file-name sort/reverse message-directory [
<<quoted lines omitted: 42>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein
[12/12] from: gjones05:mail:orion at: 30-Mar-2001 13:17
From: <[ryan--christiansen--intellisol--com]>
> >> message-block: copy []
> >> foreach file-name sort/reverse message-directory [
<<quoted lines omitted: 22>>
> ]
> wouldn't accomplish the same thing. I'd like to know, too.
Actually, I do see, now. I typed the wrong block name! What a "block"
headed manuveur ;-). I meant to explain was this:
message-block: copy []
sort/reverse message-directory
foreach file-name message-directory [
file-contents: read file-name
insert message-block file-contents
]
Sorry for the confusion. I use a similar file name scheme, and sorted it as
such. But when I translated it into your names, I typed the wrong block
name. I should have typed out the code segment, and then I would have more
easily seen my own error. Beside's, Anton's version is cleaner by one
command!
I suspect that the reason that "sort/reverse message-block" within the
foreach loop didn't work had to do with what may have been the first line in
the file content block. I don't recall the order of the messages in the
test page you had set up yesterday, but could it have been sorting on a
first line that was not the date? Just a thought.
Thanks for the reply. Now I understand my error.
--Scott Jones
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted