# Directory listing

**URL:** <https://www.ruby-forum.com/t/directory-listing/72236>\
**Category:** Rails\
**Created:** [October 15, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/directory-listing/72236 "2006-10-15T22:29:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [October 15, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/directory-listing/72236/1 "2006-10-15T22:29:15Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [October 15, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/directory-listing/72236/2 "2006-10-15T23:23:16Z")

</div>

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  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– Reliability, Ease of Use, Scalability  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [October 15, 2006, 11:43pm UTC](https://www.ruby-forum.com/t/directory-listing/72236/3 "2006-10-15T23:43:20Z")

</div>

Something like this ought to suffice…

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

-christos

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [October 16, 2006, 6:56am UTC](https://www.ruby-forum.com/t/directory-listing/72236/4 "2006-10-16T06:56:08Z")

</div>

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
