#script shell #---------------------- echo Removing $1 rm -r $1 echo Creating $1 mkdir $1 #java method /** * Remove a directory using shell command * @param scriptFileName shell script containing the command * @param inputDir directory to be removed and newly created **/ public static void RemoveAndMakeDir(String scriptFileName, String inputDir) { File d = new File(inputDir); if (d.isDirectory()) { try { Runtime rt = Runtime.getRuntime(); // Process pr = rt.exec("cmd /c dir"); System.out.println("Removing and Recreating directory '" + inputDir + "'"); Process pr = rt.exec(scriptFileName + " " + inputDir); pr.waitFor(); } catch (Exception e) { System.out.println(e.toString()); e.printStackTrace(); } } else { d.mkdir(); } }
Log in to post a comment.
Last edit: Duy Dinh 2014-04-11