【问题标题】:Last write time of directory or fileset in NAntNAnt 中目录或文件集的最后写入时间
【发布时间】:2012-07-08 02:19:02
【问题描述】:

NAnt 有 directory::get-last-write-timefile::get-last-write-time,但我正在寻找一种方法来获取目录(递归)或文件集中任何文件的最近写入时间。

directory::get-last-write-time 可能看起来很有用,但只有在直接写入目录中的文件而不是子目录中的文件时才会更新。

有没有办法用股票 NAnt 做到这一点,或者我是否必须编写一些东西来递归目录/文件集的所有内容并找到最近的写入时间?

【问题讨论】:

    标签: file directory nant


    【解决方案1】:

    您可以使用 NAnt 使用普通的旧 <foreach> 循环来执行此操作。有点尴尬,但它有效:

    <target name="go">
      <fileset
        id="paths"
        basedir="C:\foo">
        <include name="**/*" />
      </fileset>
      <!-- preset with Unix epoch -->
      <property
        name="most.recent"
        value="1970-01-01T00:00:00Z" />
      <foreach item="File" property="path">
        <in>
          <items refid="paths" />
        </in>
        <do>
          <property
            name="current"
            value="${file::get-last-write-time(path)}" />
          <property
            name="most.recent"
            value="${current}"
            if="${datetime::parse(current) > datetime::parse(most.recent)}" />
        </do>
      </foreach>
      <echo message="${most.recent}" />
    </target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多