Java tutorial
//package com.java2s; import java.io.File; public class Main { synchronized public static int clearFolder(File path) { int deletedItems = 0; File[] fileList = path.listFiles(); if (fileList != null) { for (File file : fileList) { if (file.isDirectory()) { deletedItems += clearFolder(file); } if (file.delete()) { deletedItems++; } } } return deletedItems; } }