Display executable files in directory C# Exercise - C# Programming Course

 Exercise

Display executable files in directory

 Objetive

Create a program that shows the names (excluding the path) of all executable files (.com, .exe, .bat, .cmd) in the current folder.

 Example 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;
            }
        }
    }
}

Juan A. Ripoll - Programming Tutorials and Courses © 2024 All rights reserved.  Legal Conditions.