<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: newer code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 18 Aug 2008 03:54:56 GMT</pubDate>
    <description>DZone Snippets: newer code</description>
    <item>
      <title>Which file is the newest?</title>
      <link>http://snippets.dzone.com/posts/show/1270</link>
      <description>&lt;code&gt;&lt;br /&gt;    newest: func [&lt;br /&gt;        {Returns the target with the most recent modification. Targets must be&lt;br /&gt;        file! or URL! values. If multiple targets have the same timestamp, the&lt;br /&gt;        last one found will be considered the newest.}&lt;br /&gt;        targets [any-block!]&lt;br /&gt;;        /local newest-date tgt-date result&lt;br /&gt;        /local result&lt;br /&gt;    ][&lt;br /&gt;        ; Take 1&lt;br /&gt;;         newest-date: 1-Jan-0000&lt;br /&gt;;         foreach target targets [&lt;br /&gt;;             if greater-or-equal? tgt-date: modified? target newest-date [&lt;br /&gt;;                 newest-date: tgt-date&lt;br /&gt;;                 result: target&lt;br /&gt;;             ]&lt;br /&gt;;         ]&lt;br /&gt;;         result&lt;br /&gt;        ; Take 2 - No optimization for checking timestamps multiple times&lt;br /&gt;        ;          but much clearer.&lt;br /&gt;        result: first targets&lt;br /&gt;        foreach target next targets [&lt;br /&gt;            result: newer target result&lt;br /&gt;        ]&lt;br /&gt;        result&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 01:58:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1270</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Which file is newer? (returns target, not logic)</title>
      <link>http://snippets.dzone.com/posts/show/1269</link>
      <description>&lt;code&gt;&lt;br /&gt;    newer: func [&lt;br /&gt;        {Returns the newer of the two targets. Returns target-2 if their&lt;br /&gt;        timestamps are the same.}&lt;br /&gt;        target-1 [file! url!]&lt;br /&gt;        target-2 [file! url!]&lt;br /&gt;        /local exists-1? exists-2?&lt;br /&gt;    ][&lt;br /&gt;        set [exists-1? exists-2?] reduce [exists? target-1 exists? target-2]&lt;br /&gt;        if all [(not exists-1?) (exists-2?)] [return target-2]&lt;br /&gt;        if all [(not exists-2?) (exists-1?)] [return target-1]&lt;br /&gt;        if all [(not exists-1?) (not exists-2?)] [return none]&lt;br /&gt;        either newer? target-1 target-2  [target-1] [target-2]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 01:57:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1269</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>Which file is newer?</title>
      <link>http://snippets.dzone.com/posts/show/1268</link>
      <description>&lt;code&gt;&lt;br /&gt;    newer?: func [&lt;br /&gt;        {Returns true if target-1 was modified more recently than target-2;&lt;br /&gt;        false otherwise.}&lt;br /&gt;        target-1 [file! url!]&lt;br /&gt;        target-2 [file! url!]&lt;br /&gt;    ][&lt;br /&gt;        if not exists? target-1 [return false]&lt;br /&gt;        either any [&lt;br /&gt;            all [&lt;br /&gt;                (not none? modified? target-1)&lt;br /&gt;                (none? modified? target-2)&lt;br /&gt;            ]&lt;br /&gt;            (greater? modified? target-1 modified? target-2)&lt;br /&gt;        ] [true] [false]&lt;br /&gt;    ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jan 2006 01:56:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1268</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
  </channel>
</rss>
