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 Newer? (returns Target, Not Logic)

01.22.2006
| 1379 views |
  • submit to reddit
        
    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]
    ]