From: "Mark J. Reed" Date: 2003-10-02T12:44:58+09:00 Subject: Re: Getting a list of the files in a directory On Wed, Oct 01, 2003 at 08:01:21PM -0700, 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? It's in the Dir class, not the File class, which is why you didn't see it. :) The easiest way is probably to use foreach and do your renaming in the block you pass to it: Dir.foreach(pathname) do |f| # do whatever you want with f, which is a filename within the # given directory (not fully-qualified) end