System:
Windows Server 2008 Ruby 192
in ‘delete’: Permission denied Errno:EACCES
the line: File.delete(‘filename.ext’)
If you know any other method to delete the file bypassing this error I’m glad to distribute you some points 🙂 I mean any help would be appreciated ;-p
I was suspecting that file wasn’t closed but it is closed.
Source code:
Dir.foreach(FileUtils.pwd()) do |f|
a[i] = f
if a[i].end_with?('log')
file = File.open(a[i])
if file.ctime < TIME_TO_REMOVE_LOGS || file.mtime < TIME_TO_REMOVE_LOGS || File.size(a[i]) > MAX_FILE_SIZE
puts a[i]
puts file.ctime
puts file.mtime
# zipping the file
orig = a[i]
Zlib::GzipWriter.open('arch_log.gz') do |gz|
gz.mtime = File.mtime(orig)
gz.orig_name = orig
gz.write IO.binread(orig)
end
file.close
end
end
File.delete(a[i])
i = i + 1
end
It’s not closed. The file only gets closed sometimes depending on ctime. There’s a lot wrong with your code but the main point is this: be safe with your files and use a block.
Also give your variables better names.