File.addmod?

R

Roger Pack

I'm familiar with
File.chmod 0777 filename

however, anybody know the equivalent to "chmod u+r filename" from the
command line--but in ruby?
Thanks!
-r
 
R

Rob Biedenharn

I'm familiar with
File.chmod 0777 filename

however, anybody know the equivalent to "chmod u+r filename" from the
command line--but in ruby?
Thanks!
-r
File.class_eval do
def self.addmod(flags, filename)
themode=stat(filename).mode | flags
chmod(themode, filename)
end
end

Although there's no error checking and the return value could probably
be something better (like themode).

So after defining that, your 'u+r' would be:
File.addmod(0200, 'filename')


-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
R

Roger Pack

File.class_eval do
def self.addmod(flags, filename)
themode=stat(filename).mode | flags
chmod(themode, filename)
end
end

Although there's no error checking and the return value could probably
be something better (like themode).

So after defining that, your 'u+r' would be:
File.addmod(0200, 'filename')

Much thanks.
-r
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,446
Latest member
Pycoder

Latest Threads

Top