Use Directory.GetFiles(...);
I'd do this to start with:
ArrayList GetUnionFileList ( string path, string extension1, string
extension2 )
{
ArrayList unionList = new ArrayList();
try
{
string[] filesWithExt1 = Directory.GetFiles ( path,
extension1 );
string[] filesWithExt2 = Directory.GetFiles ( path,
extension2 );
foreach ( string file1 in filesWithExt1 )
{
foreach ( string file2 in filesWithExt2 )
{
if ( Path.GetFileNameWithExtension (
file1 ).ToLower() == Path.GetFileNameWithExtension ( file2 ).ToLower() )
{
unionList.Add ( Path.GetFileNameWithExtension
( file1 ) );
break;
}
}
}
}
catch ( Exception ex )
{
// handle the exception here
}
finally
{
return unionList;
}
}
This will be a slow algorithm for lots of files, so I'd look for ways to
improve it. (EG, removing each found item from the array so they're not
searched again).
Hope that helps.
Dan.
"Mullin Yu" <mu*******@ctil.com> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl...
e.g. c:\test
doc1.txt
doc1.pdf
doc2.txt
doc2.pdf
doc3.txt
doc4.pdf
doc5.txt
doc5.pdf
only doc1, doc and doc5 will be returned as has both .txt and .pdf files
how to implement? i'm not sure whether the DirectoryInfo's GetFileInfo's
seach pattern can do so or not?