From: Dave Brondsema Date: 2000-12-10T03:10:02+09:00 Subject: [ruby-talk:6976] Re: Dir.sort(somedir) ? In article <3A31BA04.317C0AC8@groupdigital.com>, Keith Weinberg wrote: > try > > Dir.entries("thisdir").sort.each do |filename| > # get down 'n dirty > end > > The Dir.entries("dirname") gives you an array of filenames, which can be > sorted > and then acted on individually. Just what I needed. Thanks. > > /< > > Dave Brondsema wrote: > > > > I just started experimenting with Ruby tonight and have written a > > decent sized program in just a few hours. > > > > I have a question though. I currently do a loop through all the files > > in a directory using the following (I like Ruby's iterators, btw): > > > > Dir.foreach(thisdir) { > > |filename| > > # do stuff with filename > > } > > > > How can I change this so that it iterates through the alphabetically > > sorted directory? > > > > If I could get the directory into an array, I think I could sort it > > using arrayname.sort and then iterate through it. However, I don't > > even know how to do that. > > > > Thanks in advance, > > > > -- > > Dave Brondsema > > > > Sent via Deja.com http://www.deja.com/ > > Before you buy. > -- Dave Brondsema Sent via Deja.com http://www.deja.com/ Before you buy.