public class Test {
public static void main(String args[]){
File file=new File("C:\\Users\\Administrator\\Desktop\\123");
System.out.println("指定路径为: "+file.getName());
String path="C:\\Users\\Administrator\\Desktop\\123\\ed";
CharSequence path1= path;
String ppath=findDir(file,path1);
System.out.println(ppath);
}
public static String findDir(File file,CharSequence path1){
//如果路径可以使用那么判断路径下的文件夹
if(file.exists()){
File[] files=file.listFiles();
for(int i=0;i<files.length;i++)
{
if(files[i].isDirectory()){
//如果发现是文件夹那么,判断获取其路径信息并且进行判断
String temp=null;
try {
//获得当前文件夹的路径
temp = files[i].getCanonicalPath();
//System.out.println("文件夹路径为:"+files[i].getCanonicalPath());
//temp=temp.replace("\\","\\\\");
//System.out.println("path1:"+path1);
if(temp.contains(path1)){
System.out.println("!!!!!!!");
return temp;
}
} catch (IOException e) {
}
}
}
}
return null;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
需要传入的是一个路径
路径是 原始的我们定义的path 也就是logs\log123456
因此在ant扩展中
private String comparePath; (我们要拿的path)这个每次是不一样的 根据lastbudild来
private String path; (也就是上一级路径这个可以写死)
private String propertyName; (这个是处理后需要返回的值)
//针对 comparePath 和 path 直接生成 setter getter
public void setProperty(String propertyName) {
this.propertyName = propertyName;
}
/* public void execute(){
//这里实际上是给 property赋值的也就是传回的
getProject().setNewProperty(this.propertyName, "test change value in own task");
} */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
注意生成ant扩展包, wc目录下 build.xml 修改两部分 一个是exclude 一个是单独的 dest
生成后导入到相应的路径下
最后修改一下 将所有依赖包放置到 tool中
转侧文档
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<GetPath
property="getpath" //要传回来的值
path="";//这一级别到log
comparePath="${propArg}"//这一级到 lastbuild
/>
<echo message="------------------- ${getpath} -------------------------------------" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在扩展里这样写,注意getter setter 就可以了
http://www.oschina.net/question/234345_51227?fromerr=1Ho5lT7l
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class GetPath{
private String comparePath; (我们要拿的path)这个每次是不一样的 根据lastbudild来
private String path; (也就是上一级路径这个可以写死)
private String propertyName; (这个是处理后需要返回的值)
//生成setter getter
public void setProperty(String propertyName) {
this.propertyName = propertyName;
}
public void execute(){
File file=new File(path);
System.out.println("指定路径为: "+file.getName());
String path=comparePath;
CharSequence path1= path;
String returnPath=findDir(file,path1);
getProject().setNewProperty(this.propertyName, returnPath);//将returnPath的值传回到ant 插件中
System.out.println("返回的路径:"+returnPath);
}
public String findDir(File file,CharSequence path1){
//如果路径可以使用那么判断路径下的文件夹
if(file.exists()){
File[] files=file.listFiles();
for(int i=0;i<files.length;i++)
{
if(files[i].isDirectory()){
//如果发现是文件夹那么,判断获取其路径信息并且进行判断
String temp=null;
try {
//获得当前文件夹的路径
temp = files[i].getCanonicalPath();
//System.out.println("文件夹路径为:"+files[i].getCanonicalPath());
//temp=temp.replace("\\","\\\\");
//System.out.println("path1:"+path1);
if(temp.contains(path1)){
System.out.println("!!!!!!!");
return temp;
}
} catch (IOException e) {
}
}
}
}
return null;
}
}
里面的处理是自动获取当前路径下的文件夹