ListDirectory with file pattern

Advertisement

Vara04
Joined:
Posts:
5
Location:
France

ListDirectory with file pattern

Hello,

How can I list on remote FTP server : /mydir/*.csv
It works fine with /mydir but not with file pattern :-\

Any solution ?

ok I can list all files and after filter them but if there is a better solution ;-)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: ListDirectory with file pattern

It is not supported and most protocols do not support filtering listing on the server side anyway.
So do it yourself.

Reply with quote

Vara04
Joined:
Posts:
5
Location:
France

If I can help :

This is how it can be done :

Regexp construction pattern : see PJ

Loop on file return by ListDirectory with a new parameter pattern

RemoteDirectoryInfo v_RemoteDirectoryInfo = session.ListDirectory(path);
Regex v_Regex = FTPClientBeanCommandFTP.FindFilesPatternToRegex.Convert(pattern);
List<RemoteFileInfo> v_ListFile = new List<RemoteFileInfo>();
foreach (RemoteFileInfo v_RemoteFileInfo in v_RemoteDirectoryInfo.Files)
{
   if ((!v_RemoteFileInfo.IsDirectory)
      && (v_Regex.IsMatch(v_RemoteFileInfo.Name)))
   {
      v_ListFile.Add(v_RemoteFileInfo);
   }
}
 
// This can not be done because ".Files" is read only
v_RemoteDirectoryInfo.Files.Clear();
foreach (RemoteFileInfo v_RemoteFileInfo in v_ListFile)
{
   v_RemoteDirectoryInfo.Files.Add(v_RemoteFileInfo);
}

So it can be call like this :
RemoteDirectoryInfo v_RemoteDirectoryInfo = session.ListDirectory("/TestFTP", "*.CSV");

Reply with quote

Advertisement

You can post new topics in this forum