I am using Ruby and need to detect whether a directory is writeable before trying to create new files.
I have tried the following code, which correctly returns true/false depending on whether @path is a directory. However, it still returns true when there is no write permission to the @path folder.
  if File.directory?(@path) && File.writable?(@path)
    #is a writeable directory
    true
  else
    #is not a writeable directory
    false
  end
I have looked at the help for the File and Dir classes and cannot see any method that allows me to check directory write permissions. Is there a way?
I only need it work on Windows, using Ruby 1.9.3.
For Windows you want the File.attributes or File.readonly? methods from the win32-file gem.
And you should consider contributing to Daniel Berger, as without his win32- gems Ruby on Windows would be a far more hostile place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With