Hi All,
..NET 1.1... I'm wondering if there is any approach more convenient to get a
list of FileInfo objects than the following. For example, if I wanted to get
1 list of all the Exe's and all the Dll's and all the Txt's in a folder, if
appears I need to do something like the following:
ArrayList InterestingFiles = new ArrayList();
DirectoryInfo di = new DirectoryInfo(@"C:\My Folder");
FileInfo[] EXEs = di.GetFiles("*.exe");
FileInfo[] DLLs = di.GetFiles("*.dll");
FileInfo[] TXTs = di.GetFiles("*.txt");
InterestingFiles.AddRange(EXEs);
InterestingFiles.AddRange(DLLs);
InterestingFiles.AddRange(TXTs);
foreach(FileInfo fi in InterestingFiles)
{
MessageBox.Show(fi.Name);
}
It would be really cool if the GetFiles method accepted an array of
searchPatterns to accomplish this in 1 line instead of 6... but alas I can
not find anything like the following.
eg,
string[] exts = {"*.exe", "*.dll", "*.txt"}
FileInfo[] AllInterestingFiles = di.GetFiles(exts);
This would be especially more convenient when the list of file extensions we
cared about was rather long. I suppose I could write a simple
FileInfoCollection class whose constructor accepted the array of exts and a
path, but that sort of seems like overkill. Anyone have any better ideas?
I realize that I probably should use a collection of FileInfo objects
instead of an array list for the real thing, but for this example purpose
I'm being lazy <g>.
TIA,
--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com