2011-05-26 79 views
0

的情况如下:我们如何使用ant脚本来提取文件的文件扩展名?

Therea三个文件:

TEST.XLS 的test.txt Test.doc的

我与mqfte现在的工作。当这些文件被转移到另一个位置的文件名必须是如下:

result_xls.txt result_txt.txt result_doc.txt

任何人都可以在这方面的帮助?

这个文件名重命名可以用ant脚本完成吗?

回答

1

试试这个:

<target name="test"> 
    <copy todir="dest"> 
    <fileset dir="src"> 
     <include name="test*"/> 
    </fileset> 
    <globmapper from="test.*" to="result_*.txt"/> 
    </copy> 
</target> 

输入:

$ find src 
    src 
    src/test.doc 
    src/test.txt 
    src/test.xls 

出把:

$ find dest/ 
    dest/ 
    dest/result_doc.txt 
    dest/result_txt.txt 
    dest/result_xls.txt 
+0

谢谢sudocode !!!!! – trilawney 2011-05-26 12:51:30

+0

你能为下面的问题提出建议吗?http://stackoverflow.com/questions/5870083/to-display-a-read-error-when-the-source-file-is-used-by-other-applications-while – trilawney 2011-05-26 13:03:35

+0

当我在与filecopy任务相同的目标中的filecopy任务之后使用以下代码时,它不起作用。请注意,文件拷贝中的结果属性是推迟的。是由于结果=推迟的问题。 – trilawney 2011-05-30 13:28:56

0

当然,你可以使用移动Ant任务http://ant.apache.org/manual/Tasks/move.html

+0

你的意思是我应该使用全球映射?应该有三个不同的目标?我怎样才能提取每个文件的文件扩展名? – trilawney 2011-05-26 10:58:40

+0

我想我会尝试使用正则表达式映射器而不是glob,http://ant.apache.org/manual/Types/mapper.html – 2011-05-26 11:06:10

+0

您能否详细说明如何完成这项工作.... – trilawney 2011-05-26 11:41:10

相关问题