Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.5k views
in .NET FTP by (1.4k points)
Is there a way to return just, say last 10 files in a folder, by date modified, using GetFileInfos. This works great, but in this case I only need to return just the last 10 files placed in the folder and not all files. I iterate the array returned and fill a standard listview. Since there may be up to 12000 files in this folder (not under my control) this could be very slow to fill the GetFileInfos array of type FTPFile and slower yet to fill the listview. Any thoughts on a better approach using this library? I am using licensed Pro version

3 Answers

0 votes
by (51.6k points)
The FTP standard has no provision for filtering directory listings, but GetFileInfos will pass any arguments it is given on to the server. So if your FTP server supports wildcards, or perhaps some other form of filter, then you can try to pass such a filtering argument to GetFileInfos. Which server are you using?

Needless to say, having 12,000 files in a single directory is not ideal, so if you have any control over it, it might be an idea to rethink your directory structure.

- Hans (EnterpriseDT)
0 votes
by (1.4k points)
thanks for the reply,


the server is ws_ftp server. I am not familer with anything beyond standard ftp stuff with this server.
I agree 12K files is to much, but not under our control <sigh>.
I did find a kind of work around that is responsive and limits files.

i do get the ftpfile object back and it does not take that long. the killer is the listview. So i need to pare the list to 10 items.
So what I want to do is sort the returned array.

Dim items() As FTPFile = ftp.GetFileInfos()

items.sort????

then iterate the sorted array instead of file collection

For x As Integer = 0 To 10
Dim item As UltraListViewItem = Me.UltraListView3.Items.Add(items(x).Name, items(x).Name)
Next x


this works great except I haven't been able to figure how to sort the array correctly, descending on the lastmodified key of items.
Any examples of how to sort your ftpfile array?
0 votes
by (51.6k points)
There are many ways to do this. One is to define a comparer class as follows:
Public Class FTPFileComparer
    Implements IComparer(Of FTPFile)
    Public Function Compare(ByVal x As FTPFile, ByVal y As FTPFile) As Integer
        Return DateTime.Compare(x.LastModified, y.LastModified)
    End Function
End Class

and then use it as follows:
Array.Sort(items, FTPFileComparer())


- Hans (EnterpriseDT)

Categories

...