Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all file names in a directory with ruby [duplicate]

Tags:

ruby

Possible Duplicate:
Get names of all files from a folder with Ruby

I'm new to Ruby and I'm trying to get all the file names from a specific directory. There is only one level, and just need to get the entire list of names. How do I do that? I've looked at some of the other posts on the subject, but none helped.

like image 614
BlackHatSamurai Avatar asked Oct 04 '12 00:10

BlackHatSamurai


2 Answers

To list all the entries in the current directory:

Dir.entries('.')
like image 145
pje Avatar answered Nov 07 '22 05:11

pje


Dir.new('.').each {|file| puts file }

Note that this will include . and ..

like image 45
mdeltito Avatar answered Nov 07 '22 05:11

mdeltito