Chmod -R u+X in ruby

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

Tammo T. wrote:

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)

Phlip wrote:

Tammo T. wrote:

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)

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

Tammo T. wrote:

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’.