How to detect ftp file name is a directory?

扶醉桌前 提交于 2020-01-02 09:52:33

问题


In Java I'm trying to delete a ftp directory. But if it's not empty, 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?


回答1:


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!




回答2:


Take a look of this : http://www.example-code.com/java/ftp_deleteTree.asp



来源:https://stackoverflow.com/questions/4986084/how-to-detect-ftp-file-name-is-a-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!