Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Which file is the newest?

    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
        ]
        result
    ]

Which file is newer? (returns target, not logic)

    newer: func [
        {Returns the newer of the two targets. Returns target-2 if their
        timestamps are the same.}
        target-1 [file! url!]
        target-2 [file! url!]
        /local exists-1? exists-2?
    ][
        set [exists-1? exists-2?] reduce [exists? target-1 exists? target-2]
        if all [(not exists-1?) (exists-2?)] [return target-2]
        if all [(not exists-2?) (exists-1?)] [return target-1]
        if all [(not exists-1?) (not exists-2?)] [return none]
        either newer? target-1 target-2  [target-1] [target-2]
    ]

Which file is newer?

    newer?: func [
        {Returns true if target-1 was modified more recently than target-2;
        false otherwise.}
        target-1 [file! url!]
        target-2 [file! url!]
    ][
        if not exists? target-1 [return false]
        either any [
            all [
                (not none? modified? target-1)
                (none? modified? target-2)
            ]
            (greater? modified? target-1 modified? target-2)
        ] [true] [false]
    ]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS