[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

chmod -R u+X in ruby

Tammo Tjarks

7/26/2008 11:19:00 AM

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


3 Answers

Phlip

7/26/2008 1:47:00 PM

0

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

7/26/2008 2:15:00 PM

0

Phlip wrote:

> 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)

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

7/28/2008 12:24:00 AM

0

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