From: ChrisKaelin Date: 2007-04-09T15:00:09+09:00 Subject: Re: File.delete -> Permission denied On 8 Apr., 21:36, Antoine De Groote wrote: > Hello, > > I'm new to Ruby (coming from Python) and I already have trouble. > > The following code (on Windows XP, Ruby 1.8.5): > > Dir.chdir 'c:/documents and settings/antoine/desktop' > Dir.mkdir 'test' > Dir.chdir 'test' > %w{ a b c }.each { |f| File.open(f+'.txt', 'w').close } > Dir.foreach('.') { |f| File.delete f } > > throws this error message: > > problem.rb:5:in `delete': Permission denied - . (Errno::EACCES) > from problem.rb:5 > from problem.rb:5:in `foreach' > from problem.rb:5 > > I've tried to find an answer to this strange behaviour for a couple of > hours now, but I can't find one. Could anybody point me to a solution of > the problem? > > Kind regards, > antoine I had the same problem with the logfiles on my script-framework. They just could not be deleted on windows, until I tried to close them explicitly after any usage. I don't know windows file-locking mechanism, but closing any open file(handles) will save you troubles anyway. In your code above, you are doing a close, but right after opening, maybe that's a problem?