1 5 package org.h2.tools; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Constants; 10 import org.h2.util.FileUtils; 11 12 17 18 public class DeleteDbFiles extends FileBase { 19 20 private boolean quiet; 21 22 private void showUsage() { 23 System.out.println("java "+getClass().getName()+" [-dir <dir>] [-db <database>] [-quiet]"); 24 } 25 26 40 public static void main(String [] args) throws SQLException { 41 new DeleteDbFiles().run(args); 42 } 43 44 private void run(String [] args) throws SQLException { 45 String dir = "."; 46 String db = null; 47 boolean quiet = false; 48 for(int i=0; args != null && i<args.length; i++) { 49 if(args[i].equals("-dir")) { 50 dir = args[++i]; 51 } else if(args[i].equals("-db")) { 52 db = args[++i]; 53 } else if(args[i].equals("-quiet")) { 54 quiet = true; 55 } else { 56 showUsage(); 57 return; 58 } 59 } 60 execute(dir, db, quiet); 61 } 62 63 71 public static void execute(String dir, String db, boolean quiet) throws SQLException { 72 DeleteDbFiles delete = new DeleteDbFiles(); 73 delete.quiet = quiet; 74 delete.processFiles(dir, db, !quiet); 75 } 76 77 protected void process(String fileName) throws SQLException { 78 if(quiet || fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) { 79 FileUtils.tryDelete(fileName); 80 } else { 81 FileUtils.delete(fileName); 82 } 83 } 84 85 protected boolean allFiles() { 86 return true; 87 } 88 89 } 90 | Popular Tags |