How to detect ftp file name is a directory?
In Java I'm trying to delete a ftp directory. But if it's not emp开发者_如何学Pythonty, I need to delete all files and sub-dirs in it, by calling files[]=ftp.dir()
. I can get a list from the dir, but how can I tell if one of the items in the list is a file or sub-dir ? Is there a files[i].IsDirectory
method in ftp command?
I would use apache FTP Client for this. In that library there is a method called listFiles() that returns an array of FTPFile. For each FTPFile
you can call the getType() method to determine the type code constant for a directory or a file. Quote from the java docs of getType():-
public int getType()
Return the type of the file (one of the _TYPE constants), e.g., if it is a directory, a regular file, or a symbolic link.
Returns:
The type of the file.
Hope this helps!
Take a look of this : http://www.example-code.com/java/ftp_deleteTree.asp
精彩评论