From: 7stud -- Date: 2007-10-21T15:41:02+09:00 Subject: Re: Problem using FileUtils to sort JPEG files forgottenwizard wrote: > The error I keep getting these error messages: > > Exception 'Errno::ENOENT' at /usr/lib/ruby/1.8/fileutils.rb:1420 - no > such file or directory - to> > > Any clue as to the problem? 1) pix is already a string, so doing this: #{pix}" is unnecessary. 2) The following causes a syntax error: If File.directory?(filetype) then To see a similar syntax error, try this: num = 10 If num == 10 print 'yes' end 3) Your default loop probably should be each(), unless you have a specific reason to use another loop: Dir.glob("*.{jpeg,jpg,png}").each do |fname| A for-loop has a different scope than each(), i.e. it does not create a new scope. An each() loop creates a new scope, although it is leaky(see example below). 4) I couldn't find any documentation for the RMagick format() method, which is pretty typical of the horrible ruby documentation, however this works error free for me: require 'fileutils' Dir.chdir("../some_dir") workdir = Dir.pwd #outside of each block Dir.glob("*.{jpeg,jpg,png}").each do |fname| filetype = fname.split(".")[-1] if File.directory?(filetype) FileUtils.move(fname, "#{workdir}/#{filetype}") #workdir is accessible inside each() else Dir.mkdir(filetype) FileUtils.move(fname, "#{workdir}/#{filetype}") end end -- Posted via http://www.ruby-forum.com/.