Home »
Ruby Tutorial »
Ruby Programs
Ruby program to get the list of filenames matching the specified wild card pattern
Last Updated : December 15, 2025
Problem Solution
In this program, we will get the list of filenames matching the specified wild card pattern and print the result.
Program/Source Code
The source code to get the list of filenames matching the specified wild card pattern is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to get the list of filenames
# matching the specified wild card pattern
filenames = Dir::entries("MyDir");
puts "All Filenames: ",filenames;
filenames = Dir::glob("MyDir/Sample*");
puts "\nFile names: ",filenames;
Output
All Filenames:
.
..
Data.txt
SampleFile1.txt
SampleFile2.txt
SampleFile3.txt
SampleFile4.txt
File names:
MyDir/SampleFile1.txt
MyDir/SampleFile2.txt
MyDir/SampleFile3.txt
MyDir/SampleFile4.txt
Explanation
In the above program, we get the list of filenames using the Dir::glob() method with a specified wild card pattern and print the result.
Ruby Directories Programs »
Advertisement
Advertisement