How to determine if a directory can be written in Ruby

I use Ruby and must determine if I can write a directory before trying to create new files.

I tried the following code that 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 do not see any method that allows me to check write permissions to the directory. Is there any way?

I need it to work on Windows using Ruby 1.9.3.

+7
source share
2 answers

For Windows, do you want File.attributes or File.readonly? from win32-file gem.

And you should consider contributing to Daniel Berger, since without his winnings Ruby on Windows would be a much more hostile place.

+3
source

Perhaps you can do this using world_writable?(filename)

http://ruby-doc.org/core-1.9.3/File.html#method-c-world_writable-3F

0
source

All Articles