Display executable files in directory Learn programming Java

Lesson:

Additional Libraries


Exercise:

Display executable files in directory 43


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:

public class Main
{
	public static void main()
	{
		String[] files = (new java.io.File(".")).list(java.io.File::isFile);

		for (String file : files)
		{
			String extension = Path.GetExtension(file);

			switch (extension)
			{
				case ".exe":
				case ".com":
				case ".bat":
				case ".cmd":
					System.out.println(file);
					break;
			}
		}
	}
}