The source code to list the name of files in the specified directory is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to list the name of files
# in a specified directory
filenames = Dir::entries("MyDir");
puts "File names: ",filenames;
Program/Source Code:
The source code to list the name of files in the specified directory is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
Output:
Explanation:
In the above program, we get the list of filenames in the MyDir directory using the Dir::entries() method and print the result.
need an explanation for this answer? contact us directly to get an explanation for this answer