How can I detect whether a directory is writeable in Ruby
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.
You might be able to do it by using world_writable?(filename)
http://ruby-doc.org/core-1.9.3/File.html#method-c-world_writable-3F
链接地址: http://www.djcxy.com/p/10360.html上一篇: 为什么碰撞难以在图形引擎中有效计算?