Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

chmod -R u+X in ruby

2 views
Skip to first unread message

Tammo Tjarks

unread,
Jul 26, 2008, 7:18:46 AM7/26/08
to
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


Phlip

unread,
Jul 26, 2008, 9:46:51 AM7/26/08
to
Tammo Tjarks 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)

Tammo Tjarks

unread,
Jul 26, 2008, 10:15:21 AM7/26/08
to
Phlip wrote:

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

Joshua Ballanco

unread,
Jul 27, 2008, 8:24:14 PM7/27/08
to
Tammo Tjarks 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'.
--
Posted via http://www.ruby-forum.com/.

0 new messages