Tony R
Tony R

Reputation: 11544

Ruby print directory flags?

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

Answers (2)

Maher4Ever
Maher4Ever

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

Gazler
Gazler

Reputation: 84180

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

sprintf("%o", File.world_readable?("/"))

Ruby 1.8.6 solution:

sprintf("%o", File.stat("/").mode) #40755

Upvotes: 1

Related Questions