show files by extension

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,
I am trying to show files of type mp3 or wma or of type both. To
show either of mp3 or wma I am doing as follows(choosing file type by
a radio button),

DirectoryInfo currentDir = new DirectoryInfo(path + "\\");
FileInfo[] allFiles;
if (MP3s.Checked == true)
allFiles = currentDir.GetFiles("*.mp3");
else if (WMAs.Checked == true)
allFiles = currentDir.GetFiles("*.wma");
else // must be both WMA and MP3
{
} // end else

Can someone tell me how to to it.


Thanks in Advance
 
Try
ArrayList a = new ArrayList(); //in System.Collections
DirectoryInfo currentDir = new DirectoryInfo(path + "\\");
if(MP3s.Checked == true) a.AddRange(currentDir.GetFiles("*.mp3");
if(WMAs.Checked == true) a.AddRange(currentDir.GetFiles("*.wma");
FileInfo[] allfiles = (FileInfo[])a.ToArray(typeof(FileInfo));
 
Thanks Bonj, that solved my problem

Bonj said:
Try
ArrayList a = new ArrayList(); //in System.Collections
DirectoryInfo currentDir = new DirectoryInfo(path + "\\");
if(MP3s.Checked == true) a.AddRange(currentDir.GetFiles("*.mp3");
if(WMAs.Checked == true) a.AddRange(currentDir.GetFiles("*.wma");
FileInfo[] allfiles = (FileInfo[])a.ToArray(typeof(FileInfo));

Xarky said:
Hi,
I am trying to show files of type mp3 or wma or of type both. To
show either of mp3 or wma I am doing as follows(choosing file type by
a radio button),

DirectoryInfo currentDir = new DirectoryInfo(path + "\\");
FileInfo[] allFiles;
if (MP3s.Checked == true)
allFiles = currentDir.GetFiles("*.mp3");
else if (WMAs.Checked == true)
allFiles = currentDir.GetFiles("*.wma");
else // must be both WMA and MP3
{
} // end else

Can someone tell me how to to it.


Thanks in Advance
 
Back
Top