简体   繁体   中英

How to detect ftp file name is a directory?

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM