package it.backbox.transaction.task;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class DeleteTask extends Task {

	private String srcFolder;
	private String deletePath;
	private String src;
	
	public void setInput(String srcFolder, String src, String deletePath) {
		this.srcFolder = srcFolder;
		this.deletePath = deletePath;
		this.src = src;
	}
	
	public DeleteTask() {
		super();
	}
	
	public DeleteTask(String srcFolder, String src, String deletePath) {
		super();
		setInput(srcFolder, src, deletePath);
	}

	@Override
	public void run() throws Exception {
		Path source = Paths.get(srcFolder);
		Path src = Paths.get(this.src);
		Path dest = Paths.get(deletePath);
		Files.move(source.resolve(this.src), dest.resolve(src), StandardCopyOption.REPLACE_EXISTING);
	}

}

@@ -49,22 +49,87 @@
 ava.
-nio.file.Files
+io.File;%0D%0Aimport java.nio.file.Files;%0D%0Aimport java.nio.file.NoSuchFileException
 ;%0D%0Ai
@@ -230,48 +230,201 @@
 n;%0D%0A
-%0D%0Apublic class DeleteTask extends Task %7B
+import java.util.logging.Level;%0D%0Aimport java.util.logging.Logger;%0D%0A%0D%0Apublic class DeleteTask extends Task %7B%0D%0A%09private static Logger _log = Logger.getLogger(DeleteTask.class.getCanonicalName());
 %0D%0A%0D%0A
@@ -1006,106 +1006,711 @@
 ath)
-;%0D%0A%09%09Files.move(source.resolve(this.src), dest.resolve(src), StandardCopyOption.REPLACE_EXISTING);
+.resolve(src);%0D%0A%09%09if (dest != null) %7B%0D%0A%09%09%09File filedest = dest.toFile();%0D%0A%09%09%09if (!filedest.exists())%0D%0A%09%09%09%09filedest.mkdirs();%0D%0A%09%09%7D%0D%0A%09%09Path srcPath = source.resolve(this.src); %0D%0A%09%09%0D%0A%09%09Files.move(srcPath, dest, StandardCopyOption.REPLACE_EXISTING);%0D%0A%09%09%0D%0A%09%09Path path = srcPath.getParent();%0D%0A%09%09while ((path.getParent() != null) && !path.equals(source)) %7B%0D%0A%09%09%09File file = path.toFile();%0D%0A%09%09%09if (file.exists() && (file.list().length == 0)) %7B%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09Files.delete(path);%0D%0A%09%09%09%09%7D catch (NoSuchFileException e) %7B%0D%0A%09%09%09%09%09_log.log(Level.FINE, %22Error deleting folder, file already deleted by another thread?%22,  e);%0D%0A%09%09%09%09%09//file already deleted by another thread?%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%09path = path.getParent();%0D%0A%09%09%7D
 %0D%0A%09%7D

fix deleting files (moving to .delete folder). now it try to delete parent folders up to "download folder".