Tim Hunter wrote:
>
> I wrote it all.
> 

Then here's a suggestion.  On the documentation page, display a link 
that says:

all RMagick methods

When the user clicks on the link, display a page with an alphabetical 
listing of all the methods in RMagick--where each listing is a link to 
the documentation for that method.  Easy peasy, Japaneasy.




forgottenwizard wrote:
> 
> Except if a file (we'll call it image) is in the dir, it won't get
> sorted, which is why I'm usin RMagick in the first place. 

Ah, I see.  I would create the directories outside the loop:

require 'fileutils'

Dir.chdir("../somedir")

filetypes = ["jpeg", "jpg", "png"]

filetypes.each do |type|
  if not File.directory?(type)
    Dir.mkdir(type)
  end
end

Then you don't have to check each file's format to see if a 
corresponding directory exists.  Then based on what Tim Hunter said, you 
can do something like this:


lookup = filetypes.inject({}) do |hash, type|
  hash[type] = true
  hash
end
#lookup = {'jpeg'=>true,'jpg'=>true,'png'=>true}

glob_str = filetypes.join(",")

Dir.glob("*.{#{glob_str}}").each do |fname|
  begin
    filetype = Magick::Image::read(pix).first.format
    #If that causes an error, then execution jumps
    #down to the rescue block below.

    if lookup[filetype]
      FileUtils.move(fname, "./#{filetype}")
    end

  rescue IOError
    #do nothing
  end
end
-- 
Posted via http://www.ruby-forum.com/.