1. Controller
@PostMapping("/projectFileDelete")
public ServerResponse projectFileDelete(@RequestParam String filePath) {
if(filePath.isEmpty())
{
return ServerResponse.createByError();
}
return projectService.projectDelete(filePath);
}
2. Service
public ServerResponse projectDelete(String filePath) {
ServerResponse serverResponse = null;
File file = new File(filePath);
if (file.exists()) {
deleteFile(file);
serverResponse = ServerResponse.createBySuccessMessage(Const.SUCCESS);
return serverResponse;
}
serverResponse = ServerResponse.createByErrorMessage(Const.ERROR);
return serverResponse;
}
public void deleteFile(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
deleteFile(files[i]);
}
}
file.delete();
}