Q:

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

belongs to collection: Ruby Directories Programs

0

In this program, we will get the list of filenames matching the specified wild card pattern and print the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby program to get the filename one by one using ... >>
<< Ruby program to delete an empty directory using Di...