Ant任务在赤目标目录重复的文件 [英] Ant task to chek duplicate file in destination directory
问题描述
我复制文件的列表从源目录到目标目录,我需要复制之前检查重复的文件名。
谢谢..
只是想知道,这会是足够的?
<副本todir =../新/目录覆盖=false的详细=真>
<文件集DIR =src_dir/>
< /复制>
由于手册说( http://ant.apache.org/manual/Tasks/ copy.html ):
详细 - 记录正在复制的文件
。
覆盖 - 覆盖现有文件,即使目标文件是较新的
。
块引用>由于这将是一个低工作溶液。否则,我认为你需要创建自己的Ant任务。
更新:
好了,我查蚂蚁副本任务的来源,我相信你能做到的要求,在子类(新Ant任务)扩展它。正如我假设你正在运行多个文件,而不是复制只是其中的一个。
所以,你需要:
- 嗯,这不是必须的,但我相信它会帮助你:下载源$ C $蚂蚁ç(您正在使用的版本),让我们假设你使用最新的一项:< A HREF =http://ant.apache.org/srcdownload.cgi相对=nofollow> HTTP ://ant.apache.org/srcdownload.cgi
- 创建自己的Ant任务。对于文档如何做到这一点,并使用它,请参阅:的 http://ant.apache.org/manual/develop.html (例如检查部分)
- 确保你的类的扩展类:
org.apache.tools.ant.taskdefs.Copy
- 覆盖超类方法doFileOperations ,因为它的Javadoc说:
实际执行文件(也可能是空目录)的副本。这是子类覆盖一个好方法。
请检查您下载和您可以implenentation类似于此源代码的方法,内容
块引用>@覆盖
保护无效doFileOperations(){
如果(fileCopyMap.size()大于0){ 枚举E = fileCopyMap.keys();
而(e.hasMoreElements()){
字符串FROMFILE =(字符串)e.nextElement();
的String [] =目的文件(字符串[])fileCopyMap.get(FROMFILE); 的for(int i = 0; I&LT; toFiles.length;我++){
字符串TOFILE =目的文件[I] 如果(fromFile.equals(TOFILE)){
日志(跳过的自我复制+ FROMFILE,冗长);
继续;
} 如果(新文件(TOFILE).exists){
日志(警告:目标文件已存在);
}
}
}
... super.doFileOperations();
}I am copying list of files from source directory to destination directory, i need to check duplicate file name before copying..
Thanks..
解决方案Just wondering, would this be sufficient?
<copy todir="../new/dir" overwrite="false" verbose="true"> <fileset dir="src_dir"/> </copy>
As manual says ( http://ant.apache.org/manual/Tasks/copy.html ):
verbose - Log the files that are being copied.
overwrite - Overwrite existing files even if the destination files are newer.
As this would be a low effort solution. Otherwise, I think you need to create your own ant task.
UPDATE:
OK, so I checked the sources of ant copy task, and I believe you can do the required by extending it in your subclass (new ant task). As I assume you're running multiple files copying instead of just one.
So you need to:
Check the method contents in the sources you downloaded and your implenentation could look similar to this:
- well this is not a must, but I believe it would help you: download source code of Ant (version you're using), let's assume you use the latest one: http://ant.apache.org/srcdownload.cgi
- create your own ant task. For docs how to do it and use it, see: http://ant.apache.org/manual/develop.html (check example section)
- make sure your class extends class:
org.apache.tools.ant.taskdefs.Copy
- override superclass method doFileOperations, as it's javadoc says:
Actually does the file (and possibly empty directory) copies. This is a good method for subclasses to override.
@Override
protected void doFileOperations() {
if (fileCopyMap.size() > 0) {
Enumeration e = fileCopyMap.keys();
while (e.hasMoreElements()) {
String fromFile = (String) e.nextElement();
String[] toFiles = (String[]) fileCopyMap.get(fromFile);
for (int i = 0; i < toFiles.length; i++) {
String toFile = toFiles[i];
if (fromFile.equals(toFile)) {
log("Skipping self-copy of " + fromFile, verbosity);
continue;
}
if (new File(toFile).exists) {
log ("Warning: dest file already exists");
}
}
}
...
super.doFileOperations();
}
这篇关于Ant任务在赤目标目录重复的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!