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.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 Zygmuntowicz -- Lead Rails Architect -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org -- Engine Yard, Serious Rails Hosting -- Reliability, Ease of Use, Scalability -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Something like this ought to suffice... path = "/Users/christos/Desktop/Rails" files = Dir.entries(path).reject { |inode| !File.file?(inode) } -christos On 15 Oct 2006, at 22:29, 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.. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Christos Zisopoulos wrote:> Something like this ought to suffice... > > path = "/Users/christos/Desktop/Rails" > files = Dir.entries(path).reject { |inode| !File.file?(inode) } > > -christosThank you. Problem solved -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---