File masks
-
I'd like to compare a user specified file mask with a given file. I can write my own function, but many of the .NET methods use this ability and I was wondering if it was hiding someplace ? So my question is simple, does anyone know of a .Net method that will allow me to compare a file and file spec (file mask) ? i.e. compare all the files in System32 to *.d??
-
I'd like to compare a user specified file mask with a given file. I can write my own function, but many of the .NET methods use this ability and I was wondering if it was hiding someplace ? So my question is simple, does anyone know of a .Net method that will allow me to compare a file and file spec (file mask) ? i.e. compare all the files in System32 to *.d??
See the
DirectoryInfo.GetFiles
method:DirectoryInfo di = new DirectoryInfo(
Environment.GetFolderPath(Environment.SpecialFolder.System));
FileInfo[] fis = di.GetFiles("*.d");
if (fis != null)
foreach (FileInfo fi in fis)
Console.WriteLine(fi.FullName);-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
See the
DirectoryInfo.GetFiles
method:DirectoryInfo di = new DirectoryInfo(
Environment.GetFolderPath(Environment.SpecialFolder.System));
FileInfo[] fis = di.GetFiles("*.d");
if (fis != null)
foreach (FileInfo fi in fis)
Console.WriteLine(fi.FullName);-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
This is the way I'm doing it now. I'm actually getting the filename off a socket. So I create a dir and write a zero-length file using the file name then use the Directory.GetFiles() method. I just didn't know if there was a method that I could specify the file name and mask and get a boolean result, or something along those lines, so I don't have to write to disk. Thanks for your help as usual Heath. -Mike
-
This is the way I'm doing it now. I'm actually getting the filename off a socket. So I create a dir and write a zero-length file using the file name then use the Directory.GetFiles() method. I just didn't know if there was a method that I could specify the file name and mask and get a boolean result, or something along those lines, so I don't have to write to disk. Thanks for your help as usual Heath. -Mike
Well, you could generate a regex out of the mask. Add "^" to the beginning. Add "$" to the end. Replace "*" with ".*". Replace "?" with ".". And that should do it. Although you'll need to escape some characters like "(", "+", "." and "[" and a lot more.