# Directory structure

**URL:** <https://www.ruby-forum.com/t/directory-structure/114594>\
**Category:** Rails\
**Created:** [September 17, 2007, 4:55am UTC](https://www.ruby-forum.com/t/directory-structure/114594 "2007-09-17T04:55:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 17, 2007, 4:55am UTC](https://www.ruby-forum.com/t/directory-structure/114594/1 "2007-09-17T04:55:36Z")

</div>

Trying to get the files in a directory structure to be read into a  
variable. Just playing around right now but would like it so that each  
file read gets entered into a database. Trying to read a folder of music  
files. I put the folder in the public folder along with the images, and  
stylesheet. Added this code to my controller:

```
@files = Dir['/public/music/']
@mp3 = @files.select{ |my_file| /(mp3|MP3)$/ =~ my_file }

```

And added thsi code to my view:

\<%= @mp3.select{ |file| /(mp3|MP3)$/ =~ file } %\>

but nada. Any suggestions? Where do I put the folder. If it is in my  
puiblic folder, am I referencing it right in my view? Thanks

-Shandy

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 17, 2007, 9:46am UTC](https://www.ruby-forum.com/t/directory-structure/114594/2 "2007-09-17T09:46:06Z")

</div>

> ```
> @files = Dir['/public/music/']
> 
> ```

just guessing, but one possible reason this isn’t working is the path  
from the controller is relative to the ‘app’ path … something like  
this should work (extremely untested):

@files = Dir[RAILS\_ROOT + ‘/public/music’]

anyway, the problem lies within.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 17, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/directory-structure/114594/3 "2007-09-17T15:21:57Z")

</div>

> @files = Dir[RAILS\_ROOT + ‘/public/music’]

I have tried that and what I get back is ‘[].’ I assume that means that  
its not finding anything in the directory even though there is stuff  
there.
