From: Stefano Crocco Date: 2007-04-09T05:05:00+09:00 Subject: Re: File.delete -> Permission denied Alle domenica 8 aprile 2007, Antoine De Groote ha scritto: > 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 can see a problem in your code, but I'm not sure whether or not it's related to the error you get (I don't have use windows, so I can't test). Dir.foreach passes to the block also '.' and '..', which represent respectively the current directory and its parent. File.delete can't deal with directories (and at any rate, I don't think you want to delete the current directory), so it raises an exception. On linux, trying to use File.delete on a directory raises a Errno::EISDIR exception, but since exceptions in the Errno module ar operating system-dependent, it may be that in windows it raises a Errno::EACCES exception. I hope this helps Stefano