import java.io.*;
class deleteRecursion
{
public static void main(String[] args)
{
File dir = new File("D:\\java_work\\PACKAGE2\\");
deleteFiles(dir, 0);
}
public static String getLevel(int level)
{
StringBuilder sb = new StringBuilder();
for (int x = 0; x<level; x++)
{
sb.insert(0," ");
}
sb.append("|--");
return sb.toString();
}
public static void deleteFiles(File dir, int level)
{
sop(getLevel(level)+dir);
level++;
File[] f = dir.listFiles();
for (int x = 0; x<f.length; x++)
{
if(f[x].exists())
{
if (!(f[x].isHidden())&&f[x].isDirectory())
deleteFiles(f[x],level);
else
sop(getLevel(level)+f[x].toString()+"--files--"+f[x].delete());
}
}
sop(getLevel(level)+dir+"--dir--"+dir.delete());
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}