You can try this code to search files in the directory:
public static void disp(string source)
{
DirectoryInfo dr = new DirectoryInfo(source);
DirectoryInfo dir = new DirectoryInfo(des);
foreach (FileInfo fs in dr.GetFiles())
{
path = fs.Extension;
switch (path)
{
case ".doc":
if (!Directory.Exists("DOC"))
{
dir.CreateSubdirectory("DOC");
}
Console.WriteLine("file" + fs.Name);
break;
case ".txt":
if (!Directory.Exists("txt"))
{
dir.CreateSubdirectory("txt");
}
Console.WriteLine("file" + fs.Name);
break;
case ".pdf":
if (!Directory.Exists("txt"))
{
dir.CreateSubdirectory("txt");
}
Console.WriteLine("file" + fs.Name);
break;
}
}
}