【问题标题】:Ant + concat + fileset: is the alphabetical order of the files preserved?Ant + concat + fileset:文件的字母顺序是否保留?
【发布时间】:2013-09-24 12:16:56
【问题描述】:

我有以下文件:

C:/test/files/1f.txt, contains the string "file1"
C:/test/files/2f.txt, contains the string "file2"
C:/test/files/3f.txt, contains the string "file3"

如果我使用以下 Ant 任务(Ant 1.6.5):

<concat destfile="C:/test/concat.txt">
    <fileset dir="C:/test/files">
        <include name="*.txt" />                      
    </fileset>
</concat>

concat.txt 的内容是否总是file1file2file3,或者文件的字母顺序可能没有保留,因此例如file2file1file3?那在 Windows、Linux 和 Solaris 操作系统上呢?

我在 Windows 上尝试过几次,似乎是的,订单被保留了,但我需要确定这一点。如果不是,您能否提供一个反例,其中不保留字母顺序?

PS:在 Ant 1.6.5 中不允许在 &lt;concat&gt; 中嵌套 &lt;sort&gt;,但仅在 Ant 1.7+ 中。

【问题讨论】:

    标签: java ant filenames concat


    【解决方案1】:

    我不认为,您可以依赖订单。但我无法提供反例。

    也许您可以使用&lt;sort&gt; 元素来强制指定顺序:

    http://ant.apache.org/manual/Types/resources.html#sort

    应该是这样的:

    <concat destfile="C:/test/concat.txt">
        <sort>
            <fileset dir="C:/test/files">
                <include name="*.txt" />                      
            </fileset>
            <name/>
        </sort>
    </concat>
    

    【讨论】:

    • 谢谢,但问题是,Ant 1.6.5 不允许在 &lt;concat&gt; 中使用 &lt;sort&gt;,而只允许 Ant 7+(我无法迁移到 Ant 7 +)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2016-01-06
    • 1970-01-01
    • 2015-12-08
    • 2019-11-02
    相关资源
    最近更新 更多