package file;
Import Java.io.File;
Deletes all files in the specified path, and all folders in the folder, excluding the folder public
class Filedel {public
static void Delallfiles (file file,string Singal) {
if (!file.exists ()) {
System.out.println ("The path is not present:" +file);
return;
}
if (singal==null| | "". Equals (Singal)) {
singal= "-";
}
SYSTEM.OUT.PRINTLN (singal+) directory ["+file.getname () +"]: ");
singal=singal+ "-";
File[] Files=file.listfiles ();
if (files.length>0) {
for (File f:files) {
if (f.isdirectory ()) {//If it is a directory
delallfiles (f, singal); Recursive
System.out.println (singal+ "directory [" +f.getname () + "] deleted");
F.delete (); Delete this folder
}
else{
System.out.println (singal+ file "+f.getname () +" "deleted");
F.delete ();
} else
}//for
}//if
else{
System.out.println ("* * * * * * * * No files in this directory * * * *)";
}
Static
@SuppressWarnings ("static-access") public
static void Main (string[] args) {
Filedel tt=new Filedel ();
Tt.delallfiles (New File ("G:\\ABC"), null);
}