Reputation: 11544
Is there a way to print the current "chmod flags" for a given Dir
in Ruby?
I'm not an expert on permissions so forgive the terminology, but I'd like to get all possible information about a directory (is it read-only, what are the permissions, etc etc).
Edit: I need this to work in Ruby 1.8.6
Upvotes: 0
Views: 841
Reputation: 1280
You could use a bit of shell:
`stat --format=%a #{Dir.pwd}`.chomp # => 755
It's not pure ruby, but I think it gets the job done.
Upvotes: 0
Reputation: 84180
http://ruby-doc.org/core-1.9.3/File.html#method-c-world_readable-3F
sprintf("%o", File.world_readable?("/"))
sprintf("%o", File.stat("/").mode) #40755
Upvotes: 1