I have got
TWO ways to solve this:
First:
public boolean directoryexist(String remoteDirectory) throws Exception{
if(remoteDirectory == null || remoteDirectory.equals("")){
return false;
}
else{
//list the root path
FTPFile[] currentdirectory = this.directoryList("..");
//Split the given remoteDirectory with "/"
String[] targetdirectory = remoteDirectory.replace('\\', '/').split("/");
boolean findit = false;
for(int i=0; i< targetdirectory.length;i++){
findit = false;
if(targetdirectory[i].equals("..") || targetdirectory[i].equals("")){
continue;
}else{
for(int j = 0; j< currentdirectory.length; j++){
//find one path
if(currentdirectory[j].isDir() && currentdirectory[j].getName().equals(targetdirectory[i])){
//change into it
this.changeDirectory(targetdirectory[i]);
//list targetdirectory[i]
currentdirectory = this.directoryList();
findit = true;
break;
}
}
}
}
return findit;
}
Second:
public boolean directoryExist(String remoteDirectory) throws Exception{
boolean ifexist = true;
if(remoteDirectory == null || remoteDirectory.equals("")){
return false;
}else{
String directory = remoteDirectory.replace('\\', '/');
try{
this.changeDirectory(directory);
}catch(FTPException e){
ifexist = false;
}
}
return ifexist;
}
I hope it will be helpful !!