Display executable files in directory Learn programming C# Sharp

Lesson:

Additional Libraries


Exercise:

Display executable files in directory 55


Objetive:

Create a program to display the name (but not the path) of the executable files (.com, .exe, .bat, .cmd) in the current directory


Code:

using System;
using System.IO;
class DisplayExecutableFiles
{
    static void Main()
    {
        string[] files = Directory.GetFiles(".");

        foreach (string file in files)
        {
            string extension = Path.GetExtension(file);

            switch (extension)
            {
                case ".exe":
                case ".com":
                case ".bat":
                case ".cmd":
                    Console.WriteLine(file);
                    break;
            }
        }
    }
}