You can Try the following C# Code
public void GetFiles(string path)
{
if (File.Exists(path))
{
ProcessFile(path);
}
else if (Directory.Exists(path))
{
{
ProcessDirectory(path);
}
}
public void ProcessDirectory(string targetDirectory)
{
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
public string ProcessFile(string path)
{
FileInfo fi = new FileInfo(path);
string sExtension = fi.Extension;
return sExtension;
}