Hi,
I'm using apache.commons.net.ftp.FTPClient to scan an FTP directory which can contain thousands of files which have been written over several months.
I'll only ever be interested in a recent subset of those files though (about a week's worth at most), but I'm having to loop through thousands of instances which is taking unacceptably long (over an hour). Is there any way that I can eliminate the older files on mass without having to painfully iterate through each one? Here's the code I'm currently using to do the date checks...
client.cwd(directory);
ftpFiles = client.listFiles(directory);
for (FTPFile ftpFile : ftpFiles) {
String name = ftpFile.getName();
if (ftpFile.getType() == FTPFile.FILE_TYPE) {
Date today = new Date();
long dateDiffHours = (today.getTime() - ftpFile.getTimestamp().getTimeInMillis())/(1000 * 60 * 60);
if (dateDiffHours>(argsQueryHours+2)){}else{
//do something with the file because it's recent enough
Any help would be really appreciated! Thanks,
Daniel