thank you for replying...
yes i tried to write my own recursive method ,but i'm still not able getting it work correctly.
below are 3 java methods.i'm using free edtftp version.
i call the method deleteDirectory(..) but it is not working..
can you help me fix my below code to make it work ?
thanks.
public static void forceDelete(FTPClient client,FTPFile file) throws Exception {
if (file.isDir()) {
deleteDirectory(client,file);
} else {
/* if (!client.exists(file.getName())) {
throw new FileNotFoundException("File does not exist: " + file);
}*/
client.delete(file.getName());
/* if (!file.delete()) {
String message =
"Unable to delete file: " + file;
throw new IOException(message);
}*/
}
}
//-----------------------------------------------------------------------
/**
* Recursively delete a directory.
*
* @param directory directory to delete
* @throws IOException in case deletion is unsuccessful
*/
public static void deleteDirectory(FTPClient client,FTPFile directory) throws Exception {
/* if (!client.exists(directory.getName())) {
return;
}*/
cleanDirectory(client,directory);
client.cdup();
client.rmdir(directory.getName());
/*if (!directory.delete()) {
String message =
"Unable to delete directory " + directory + ".";
throw new IOException(message);
}*/
}
/**
* Clean a directory without deleting it.
*
* @param directory directory to clean
* @throws IOException in case cleaning is unsuccessful
*/
public static void cleanDirectory(FTPClient client,FTPFile directory) throws Exception {
String filePath=directory.getName();
String path=null;
/*FTPFile f=(FTPFile)Utils.p_ftpFiles.get(filePath);
if(f==null)
return;*/
path=(directory.getPath()==null)? ("/"+filePath):directory.getPath();
// client.chdir(directory.getName());
/*if (!client.exists(directory.getName())) {
String message = directory + " does not exist";
throw new IllegalArgumentException(message);
}*/
if (directory.isDir() && !directory.isLink()) {
client.chdir(path);
// String message = directory + " is not a directory";
// throw new IllegalArgumentException(message);
FTPFile[] files = client.dirDetails(path);
if (files == null || files.length==0) { // null if security restricted
client.cdup();
client.rmdir(directory.getName());
}
for (int i = 0; i < files.length; i++) {
FTPFile file = files[i];
forceDelete(client,file);
}
}
}