From: Robert Klemme Date: 2003-10-02T20:25:44+09:00 Subject: Re: Getting a list of the files in a directory "Jim Freeze" schrieb im Newsbeitrag news:20031002062017.A50661@freeze.org... > On Thursday, 2 October 2003 at 12:24:25 +0900, Revision17 wrote: > > Hi, I'm just starting out with ruby and I'm writing a script to rename > > a bunch of files in a directory to a way I want them to be (just to > > get more familiar). I've looked at the documentation for the file > > class (http://www.rubycentral.com/book/ref_c_file.html), but I can't > > seem to find the method I'd use to get all the names of files in a > > directory. How can I do this? > > The easy way is to use the glogging feature of Dir#[]. > For example > > files = Dir["*"] > > To upcase all files in a directory, do: > > Dir["*"].each { |file| `mv #{file} #{file.upcase}` } > > for unix. It's similar for windows, but I don't have > a windows box to test it. Why not Dir["*"].each { |file| File.rename( file, file.upcase ) } ? robert