Posted By: pathfinder | Mar 28th, 2007 @ 9:56 AM
page 1 of 1
Comments: 3 | Views: 3588
The DirectoryInfo object has a method GetFiles(string SearchPattern) that will search a directory for any files that match the searchpattern (i.e. *.txt).  

I basically want to use this same logic, but without the DirectoryInfo object.  In other words, I just want to test a file name to a list of File Masks to determine what the file is.  So I might have a user defined file mask Accounts*.bak, and I would get a true if the file name matches.  

I tried using regular expressions, but  in regular expressions I would have to put Accounts.*\.bak  

Does anyone know of a way to do a file mask without making the user know regular expressions?

Thanks
Just use regex.

Have the user input a normal file mask, but befor you use what he have you, do this:

string fromuser = "get string from user";

fromuser = fromuser.replace(".","\\."
fromuser = fromuser.replace("*",".*");
fromuser = fromuser.replace("?",".");

Of course you also need put slashes in fronot of the other special regex chars Smiley
What don't you like about using the DirectoryInfo object?
Jorgie wrote:
Of course you also need put slashes in fronot of the other special regex chars Smiley

You can use Regex.Replace to do that for you.
page 1 of 1
Comments: 3 | Views: 3588