Display executable files in directory Java Exercise - Java 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

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


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