ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the list the name of files in a specified directory

Ruby Example: Write a program to get the list the name of files in a specified directory.
Submitted by Nidhi, on February 20, 2022

Problem Solution:

In this program, we will get the list of filenames in the specified directory and print the result.

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.

# Ruby program to list the name of files 
# in a specified directory

filenames = Dir::entries("MyDir");

puts "File names: ",filenames;

Output:

File names:
.
..
SampleFile1.txt
SampleFile2.txt
SampleFile3.txt
SampleFile4.txt

Explanation:

In the above program, we get the list of filenames in the MyDir directory using the Dir::entries() method 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.