|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Matching a string to a filename mask?fred.out inctructions.txt luncheon01.jpg luncheon02.jpg luncheon05.jpg luncheon11.jpg HeebieJeebie.cs ...etc.. The user will provide a filename mask such as: *.* *.jpg luncheon0?.* ...etc.. Is there a simple way to do a comparison of the user-defined filename masks -vs- a string? I need to return a list of the strings that matched their filename mask. The users will not know how to create RegEx expressions, only typical filename masks. At worst, I think I can convert their mask to a RegEx and match/test on that, but was hoping there was an easier way. -BEP 1) If you create your list from real files. You can use following
static method to get filtered list next time. Directory.GetFiles(string Path, string pattern) 2) You can easily convert ? and * mask to regex: Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?",".") Yury wrote:
> 1) If you create your list from real files. You can use following The filenames are cached already so I won't be able to do this. I use > static method to get filtered list next time. > Directory.GetFiles(string Path, string pattern) GetFiles() to get the original list, though. > 2) You can easily convert ? and * mask to regex: I tried this and it's -really- close to what I need. I can probably get > Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?",".") it the rest of the way. Thanks for the reply. -BEP
Other interesting topics
Transfer string data to unmanaged buffer
uint64 how to casting a object inherit form Form to another object in c# 2.0 XMLNode --> Adding an Attribute COM StdPicture-to-Image conversion Can't run a C# Program Without VS2005 Possible To Set Topmost Property In A Web Browser? Downloading files String.Split Question regarding exception.... |
|||||||||||||||||||||||