The source code to get filename one by one using Dir::foreach() method is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to get filename one by one
# using Dir::foreach() method
Dir::foreach("MyDir") {|filename| puts filename};
Program/Source Code:
The source code to get filename one by one using Dir::foreach() method 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 filenames one by one using Dir::foreach() method from a specified directory and print the result.
need an explanation for this answer? contact us directly to get an explanation for this answer