论坛首页 入门技术论坛

删除指定文件夹和文件的类,默认取消SVN或VSS关联

浏览 7478 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (1)
作者 正文
   发表时间:2009-07-26   最后修改:2009-07-26
/**
* @author zhy
*/

public class DisConnect {
public static int FOLDER_TYPE = 1;
public static int FILE_TYPE = 2;
/**
* print the point message
* @param  the point message
* */

public static void print(String msg){
   System.out.println(msg);
}
/**
* check the str is null or blank
* @param the check String
* */

public static boolean isBlankOrNull(String str){
if(str == null ||"".equals(str)){
return true;
}else{
return false;
}
}

/**
* del the folder with dirToDel in path rootDir
* @param
* rootDir  the path of del folder
* dirToDel the del folder name
* */

public static String rmDirs(String rootDir,String dirToDel,int delType){
   StringBuffer sb = new StringBuffer();
   if(DisConnect.isBlankOrNull(rootDir)){
   return "the input path is null";
   }else if(DisConnect.isBlankOrNull(dirToDel)){
   if(delType == FOLDER_TYPE){
   dirToDel = ".svn";
   }else{
   dirToDel = "vssver.scc";
   }
   }
  
   try{
   // the path is not exist
   File root = new File(rootDir);
   if(!root.exists()){
   return "path:["+rootDir+"]is not exist!\n";
    }
   // the rootDir is not a folder
    boolean isdir = root.isDirectory();
    if(!isdir){
    return "";
    }
   // get the all folder and file in path rootDir
    String[] allfiles = root.list();
   // get the file and folder is not null
    if(null != allfiles && allfiles.length >= 0){
    for(int i=0;i<allfiles.length;i++){
    File curfile = new File(rootDir+"\\"+allfiles[i]);
    // the folder or file name(allfiles[i]) is dirToDel
    if(allfiles[i].equalsIgnoreCase(dirToDel)){
    // the del type is a folder
    if(FOLDER_TYPE == delType ){
    if(curfile.isDirectory()){
    // del the folder is success
    if(DisConnect.delPhysical(curfile)){
    sb.append("the folder ["+rootDir+"\\"+allfiles[i]+"]is del success!\n");
    //del the folder is fail
    }else{
    sb.append("the folder ["+rootDir+"\\"+allfiles[i]+"]is del fail!\n");
    }
    }
    //the del type is a file
    }else if(FILE_TYPE == delType){
    if(curfile.isFile()){
    // del the folder is success
    if(DisConnect.delPhysical(curfile)){
    sb.append("the folder ["+rootDir+"\\"+allfiles[i]+"]is del success!\n");
    //del the folder is fail
    }else{
    sb.append("the folder ["+rootDir+"\\"+allfiles[i]+"]is del fail!\n");
    }
    }
    }
    }else{
    if(curfile.isDirectory()){
    sb.append(DisConnect.rmDirs(rootDir+"\\"+allfiles[i], dirToDel,delType));
    }
    }
    }
    // has not file or folder
    }else{
    // do nothing
    }
    root = null;
   }catch(Exception e){
    e.printStackTrace();
   }
   return sb.toString();
}

/**
* del the folder physics and del the sub file and folder
* @param the folder name
* */

private static boolean delPhysical(File fileToDel) throws Exception{
   boolean f = false;
   //get the all file or folder
   if(fileToDel.isDirectory()){
   String[] fl = fileToDel.list();
   //has sub file or folder
   for(int i=0;i<fl.length;i++){
    File fcur = new File(fileToDel.getAbsolutePath()+"\\"+fl[i]);
   // del the sub folder
    if(fcur.isDirectory()){
    DisConnect.delPhysical(fcur);
     fcur.delete();
    //del the sub file
    }else{
     fcur.delete();
    }
   }
   }
  // del the folder
   f = fileToDel.delete();
   return f;
}
}

   发表时间:2009-07-26  
由于操作系统是日文,所以注释不是太多,写的有点问题,望大家指正,谢谢
0 请登录后投票
   发表时间:2009-07-26  
用shell不是更方便吗
0 请登录后投票
   发表时间:2009-07-26  
对阿 bash一行命令就能搞定
0 请登录后投票
   发表时间:2009-07-26  

使用ant文件操作Task默认不会对svn等版本控制软件生成的目录进行操作
详见ant文档说明
http://ant.apache.org/manual/CoreTasks/delete.html

相关delete Task的属性说明:

Attribute Description Required
defaultexcludes Deprecated. Use resource collections. Whether to use default excludes. No, default "true"

 

0 请登录后投票
   发表时间:2009-07-26   最后修改:2009-07-26
我删svn 关联是直接用

find . -iname .svn -exec rm -rdf {} \;
0 请登录后投票
   发表时间:2009-07-26  
rikugun 写道
我删svn 关联是直接用

find . -iname .svn -exec rm -rdf {} \;


我的是
find . -type d -name ".svn"|xargs rm -rf
0 请登录后投票
   发表时间:2009-07-26  
其实装了小乌龟的windows下面用svn,可以右键,然后export的
0 请登录后投票
   发表时间:2009-07-27  
lz 你这个我好象从哪看见过 连方法名都没变呢!~
0 请登录后投票
   发表时间:2009-07-27  
我一般都用Windows搜索功能,把.svn全搜索出来,然后一块删掉。 :)
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics