I changed the function as suggested (see the function following), using
'sort/reverse on the 'message-directory, but now all of the file names are
sorted smallest to largest. Isn't this the opposite of what sort/reverse is
supposed to accomplish? This is on an IIS server. On a Linux server, using
the same statement sorts the file names largest to smallest.

Have I found a bug? Carl?

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 []
    sort/reverse message-directory
    foreach file-name message-directory [
        file-contents: read file-name
        insert message-block file-contents
        message-block
    ]
]

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
[EMAIL PROTECTED]


                                                                                       
                   
                    "GS Jones"                                                         
                   
                    <gjones05@mail.        To:     <[EMAIL PROTECTED]>              
                   
                    orion.org>             cc:                                         
                   
                    Sent by:               Subject:     [REBOL] Re: sort/reverse 
revisited                
                    rebol-bounce@re                                                    
                   
                    bol.com                                                            
                   
                                                                                       
                   
                                                                                       
                   
                    04/11/2001                                                         
                   
                    02:43 PM                                                           
                   
                    Please respond                                                     
                   
                    to rebol-list                                                      
                   
                                                                                       
                   
                                                                                       
                   




From: <[EMAIL PROTECTED]>
> I'm having fits over using sort/reverse to sort file names from a
> directory. I know we've gone over this before, but what I thought was
> working is no longer working. For example, using the following function
on
> a Linux server seems to work fine:
>
> 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
>         sort/reverse message-block
>         message-block
>     ]
> ]
>
> But on an IIS server, things get out of order. (I have no idea why.) If I
> remove...
>
> sort/reverse message-block
>
> from the above function, the IIS server behaves nicely.
>
> Is there any way to write a function which will accommodate both
situations
> nicely?
>
> All of my filenames are as such...
>
> 20010410145432
> 20010410145433
> 20010410145434
>
> and as such, there should be some way to order them.
>
> Ryan C. Christiansen
> Web Developer

Hi, Ryan,
If it is the file names that you wish to have sorted (or reverse sorted),
then the sort should be performed on the block of filenames (given that the
date-time is "encoded" in the file name).

In this case, "sort/reverse message-directory" will give a descending sort
on the block.  I would suggest trying the following:

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 []
    sort/reverse message-directory ;reverse sorts the file names before
retrieving the contents
    foreach file-name message-directory [
        file-contents: read file-name
        insert message-block file-contents ;will return block index after
the inserted content
        ; delete the following line, since it will be sorting the
*contents*
of the files
        ; sort/reverse message-block
        message-block
    ]
]

or, slightly briefer, (excepting my comments)

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 sort/reverse message-directory [
        ;append "guarantees" insertion at the tail, in case the
        ;  "index" gets messed up with added code
        append message-block read file-name
    ]
        message-block ; to return the reference to the block
]

The reason the different OS'es may give file names in varying orders was
hinted at before.  As you know, the order of file names returned by any OS
system call usually depends on the ordering of the file names in the
directory structure.  Many OS'es fill in new file names in the first
available space for the disk/directory.  When files are deleted, they open
up space in the directory structure, so that the next file written will
fill
a name in that space.  Ordering of the names depends on what's available in
the structure.  Then the actual contents of the files are filled into first
available space.  Most OS'es then allow ordering of the names through the
command line commands and/or through the GUI.

You could do the reverse sort on the message-block itself, with care, if
the
sort occurred on the correct data component.  But since the date-time is
already encoded in the file name, it is far easier to simply sort on the
name block first, in my opinion.

Assuming I didn't make a typo, like last time, I hope this helps.
--Scott Jones

--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.





-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to