Delete all empty folders under the established directory//num=0 the first time you traverse the folder num=1 the second time you traverse the folder public static void ListDirectory (File file,int num) throws Exception{if (!file.exists ()) {throw new IllegalArgumentException ("directory" +file+ "does not Exist");} else if (!file.isdirectory ()) {throw new IllegalArgumentException (file+ "is not a Directory");} else {//Enter directory file[] fl = File.listfiles (); if (Fl!=null && fl.length>0) {if (num==1) return; for (file f:fl) {if ( F.isdirectory ()) {listdirectory (f,0);} else {System.out.println (F.getname ());}} ListDirectory (file,1);//If the directory traversal is complete before traversing the next directory for file}else if (fl = = NULL | | fl.length==0) {SYSTEM.OUT.PRINTLN (File.getname () + ": Directory is Empty"); File.delete ();}}}
Delete empty folders under the specified directory