Directory listing

Hello,
I want to list all the files from a directory (but just the files, no
other directories).
Any ideas how ?
I was thinking of using lf -F and then remove all the elements that
contain the “/” character, but i have no ideea how to acomplish this.
Anyway just a thought.

Thanks…

On Oct 15, 2006, at 1:29 PM, Daniel Mircea wrote:

Hello,
I want to list all the files from a directory (but just the files, no
other directories).
Any ideas how ?
I was thinking of using lf -F and then remove all the elements that
contain the “/” character, but i have no ideea how to acomplish this.
Anyway just a thought.

Thanks…

You can use the Dir class to do that pretty easily. If you just want

a list of all files in a directory excluding any subdirectories you
can do it like this:

Dir[RAILS_ROOT+"/public/*"].reject{|f| File.directory?(f)}.map {|f|
File.basename(f) }

Cheers-

– Ezra Z.
– Lead Rails Architect
[email protected]
– Engine Y., Serious Rails Hosting
– Reliability, Ease of Use, Scalability
– (866) 518-YARD (9273)

Something like this ought to suffice…

path = “/Users/christos/Desktop/Rails”
files = Dir.entries(path).reject { |inode| !File.file?(inode) }

-christos

Christos Z. wrote:

Something like this ought to suffice…

path = “/Users/christos/Desktop/Rails”
files = Dir.entries(path).reject { |inode| !File.file?(inode) }

-christos

Thank you. Problem solved

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs