DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Which File Is The Newest?

  • submit to reddit
    newest: func [
        {Returns the target with the most recent modification. Targets must be
        file! or URL! values. If multiple targets have the same timestamp, the
        last one found will be considered the newest.}
        targets [any-block!]
;        /local newest-date tgt-date result
        /local result
        ; Take 1
;         newest-date: 1-Jan-0000
;         foreach target targets [
;             if greater-or-equal? tgt-date: modified? target newest-date [
;                 newest-date: tgt-date
;                 result: target
;             ]
;         ]
;         result
        ; Take 2 - No optimization for checking timestamps multiple times
        ;          but much clearer.
        result: first targets
        foreach target next targets [
            result: newer target result