ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the list of filenames matching the specified wild card pattern

Ruby Example: Write a program to get the list of filenames matching the specified wild card pattern.
Submitted by Nidhi, on February 21, 2022

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


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.