On Mon, 8 Oct 2007 01:19:01 +0900, Sebastian Hungerecker wrote:

> The code posted above gives you permission errors? Or your original code gives 
> you permission errors? Because the code posted above really shouldn't. If the 
> code above gives you permission error, it's not because of open file handles.

Actually, the code above should give him

TypeError: can't convert String into Integer

because IO.open wants an integer file descriptor :)  He wants Kernel.open.

The working code is:

Dir.glob("*").each do |file|
  if /%!PS-Adobe/ =~ open(file) {|f| f.gets}
    File.rename(file, file + ".eps")
  end
end

Peter, the key to Nobuyoshi's change above is that the rename now happens
*outside* the Kernel.open block.  It doesn't matter that it happens inside
the if/end block; that's not what's holding the file open - Kernel.open is.
Now, the only thing that's done in the block is the gets, and the block is
closed on the very same line, before the rename happens.

-- 
Jay Levitt                |
Boston, MA                | My character doesn't like it when they
Faster: jay at jay dot fm | cry or shout or hit.
http://www.jay.fm         | - Kristoffer