import org.apache.commons.io.FileUtils;
List<String> directory = new ArrayList();
directory.add("test-output");
directory.add("Reports/executions");
directory.add("Reports/index.html");
directory.add("Reports/report.properties");
for(int count = 0 ; count < directory.size() ; count ++)
{
String destination = directory.get(count);
deleteDirectory(destination);
}
public void deleteDirectory(String path) {
File file = new File(path);
if(file.isDirectory()){
System.out.println("Deleting Directory :" + path);
try {
FileUtils.deleteDirectory(new File(path)); //deletes the whole folder
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
System.out.println("Deleting File :" + path);
//it is a simple file. Proceed for deletion
file.delete();
}
}
Works like a Charm . For both folder and files . Salam :)