1 17 package org.eclipse.emf.ant.util; 18 19 import java.io.BufferedWriter ; 20 import java.io.File ; 21 import java.io.FileWriter ; 22 import java.io.IOException ; 23 24 25 29 public class Util 30 { 31 39 public static int removeVersion(File parentDir) 40 { 41 if (parentDir == null || !parentDir.isDirectory()) 42 { 43 return 0; 44 } 45 46 int counter = 0; 47 File [] dirs = parentDir.listFiles(); 48 for (int i = 0; i < dirs.length; i++) 49 { 50 if (dirs[i].isDirectory()) 51 { 52 String name = dirs[i].getName().replaceAll("_(\\d+\\.)+\\d$", ""); 53 if (!name.equals(dirs[i].getName()) && dirs[i].renameTo(new File (parentDir, name))) 54 { 55 counter++; 56 } 57 } 58 } 59 return counter; 60 } 61 62 68 public static void writeFile(File file, String content) throws IOException 69 { 70 if (!file.getParentFile().isDirectory()) 71 { 72 file.getParentFile().mkdirs(); 73 } 74 75 BufferedWriter out = null; 76 try 77 { 78 out = new BufferedWriter (new FileWriter (file)); 79 out.write(content); 80 } 81 finally 82 { 83 if (out != null) 84 { 85 out.close(); 86 } 87 } 88 } 89 } | Popular Tags |