0

I want to compare a filename with particular pattern or strings. Please suggest if there is a inbuilt function for the achieving this task.

Ex : file name having pattern of ".txt" or "HU.txt". Or two strings abc.txt and a*.txt.

I have to use this to get the list files from FTP so cannot use directory.getfiles(path,pattern).

My task is to download the files from FTP server which has the pattern as "HU*.txt" or can be "CZ*.txt" or can be sometimes "*.txt".

Please suggest.

Thanks

Murtaza Badshah
  • 211
  • 2
  • 5
  • 11
  • If your FTP supports `mget` you can let the remote server do the globbing. – Klas Lindbäck Nov 14 '13 at 14:56
  • Maybe this what are you looking for http://stackoverflow.com/questions/6907720/need-to-perform-wildcard-etc-search-on-a-string-using-regex – h__ Nov 14 '13 at 15:04

1 Answers1

0

You can do this using Regex.IsMatch.

For instance:

string fileName = "Something.txt";
string originalSpec = "*.txt";
string pattern = originalSpec.Replace("*", ".*?");
Regex regex = new Regex(pattern);
bool isMatch = regex.IsMatch(fileName);

Adapt this to fit your particular case and you're good to go.

Good luck!

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76