Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.6k views
in Java FTP by (320 points)
I am able to remotely login, and change directories. I am at the point where I need to get a list of just the files that end with .txt and I only want the names of those files in the array.

I am having a hard time understanding your manual. It looks like I could use listFiles() or getNames(), but there is no hint of how to use the commands to do this function.

The code I have at this point is:

// Get current directory listing
log.info("Getting current directory listing");
FTPFile[] files = ftp.directoryList(".");
for (int i = 0; i < files.length; i++) {
log.info(files[i].toString());
}

This code returns everything about all of the files in the directory.

7 Answers

0 votes
by (162k points)
The server may support ftp.directoryList("*.txt")
0 votes
by (320 points)
I now get just the information about the .txt files. Thank you.
Is there any way to just get the file name and not the rest of the data?
0 votes
by (162k points)
use directoryNameList
0 votes
by (320 points)
Bruce -
I tried replacing directoryList with directoryNameList as you suggested and I have 2 issues.
1. When I try to save the changes I get "A sharing violation occurred while accessing..." how do stop what ever is going on so I can save my changes?
2. If I re-build, I get an error "cannot find symbol" and the output of the build is pointing to "directoryNameList"
0 votes
by (320 points)
let's forget issue #1.
That is an issue with the editor I was using that just happened at the same time.
So back to directoryList and directoryNameList. Is this part of a new library or is it a seperate library?
0 votes
by (162k points)
These are both methods on FileTransferClient, which is in the existing edtftpj.jar (although a relatively recent addition).
0 votes
by (320 points)
Sould I download another copy of the package?

Categories

...