Nobuyoshi Nakada wrote:
> Hi,
> 
> At Sun, 7 Oct 2007 11:15:04 +0900,
> Peter Bailey wrote in [ruby-talk:272952]:
>> This always throws me. I keep getting "permission denied" messages when
>> I simply try to rename files. Here's my code. The files in the directory
>> start out without an extension.
>> 
>> Dir.chdir("F:/images")
> 
> Maybe on Windows?
> 
>> Dir.glob("*").each do |file|
>>   File.new(file, "r").gets
> 
> This leaves the file still opened, and on Windows, it's
> prohibited by the OS to move/rename files while they are
> opened.
> 
>     if /%!PS-Adobe/ =~ IO.open(file) {|f| f.gets}
>       File.rename(file, file + ".eps")
>     end

Yes, I'm on Windows. And, yes, it makes sense that it won't let me do it 
because the file is, apparently, still open. But, I guess I'm stumped as 
to how I can open the file to check that first line, match against that 
first line, close the file, and then be able to rename the filename of 
that particular file. Once the file is closed I really can't do anything 
more inside that same if-end loop, can I?

-Peter

-- 
Posted via http://www.ruby-forum.com/.