Daniel Berger
10/7/2007 1:23:00 PM
On Oct 7, 12:07 am, Nobuyoshi Nakada <n...@ruby-lang.org> 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
Why would he need to open the file at all?
Dir.chdir("F:/images")
Dir.glob("*").each do |file|
if file =~ /%!PS-Adobe/
newfile = file + ".eps"
File.rename(file, newfile)
end
end
Regards,
Dan