chmod -R u+X in ruby

T

Tammo Tjarks

I want to do a recursive changemod. But the chmod in File and
FileUtils allows only, at least as far as I have seen, to set
absolute file permission. But I want not to make all Files
executable and also do not want the same permissions for all files,
I want to do a "relative" change of file permissions like with
chmod -R u+X example_dir
Currently I use an
system("chmod -R u+X example_dir") and I would like to know if there is
a way to do that "naturally" in ruby.

Regards,
Tammo
 
P

Phlip

Tammo said:
Currently I use an
system("chmod -R u+X example_dir") and I would like to know if there is
a way to do that "naturally" in ruby.

A combination of Pathname.glob('example_dir/**') and Something.chmod(0766)
 
T

Tammo Tjarks

Phlip said:
A combination of Pathname.glob('example_dir/**') and Something.chmod(0766)

But then propably all files below example_dir would have the same file
permission. What I would like to accomplish is to change only one bit of
the permissions. E.g. with something like

-rw-r--r-- file1
-rwxr--r-- file2
-r-xr-x--- file3
and I want to add group write permission I would get
-rw-rw-r-- file1
-rwxrw-r-- file2
-r-xrwx--- file3

But when I use something like chmod(0766) all files have the same file
permissions afterwarts. But maybe some of them shall stay executable and
some not.

Regards,
Tammo
 
J

Joshua Ballanco

Tammo said:
Currently I use an
system("chmod -R u+X example_dir") and I would like to know if there is
a way to do that "naturally" in ruby.

You should use File.stat('filename').mode, a bitmask, and a bitwise
'and'.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top