Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > chmod -R u+X in ruby

Reply
Thread Tools

chmod -R u+X in ruby

 
 
Tammo Tjarks
Guest
Posts: n/a
 
      07-26-2008
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


 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      07-26-2008
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)
 
Reply With Quote
 
 
 
 
Tammo Tjarks
Guest
Posts: n/a
 
      07-26-2008
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



 
Reply With Quote
 
Joshua Ballanco
Guest
Posts: n/a
 
      07-28-2008
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: weird problem with os.chmod James Colannino Python 6 11-12-2005 10:33 PM
How do I CHMOD a file on a linux host? Bob K. HTML 9 07-05-2004 09:22 PM
Chmod from Runtime.Exec Brad Cooper Java 3 05-13-2004 06:55 PM
Understanding CHMOD Fuzzyman Python 6 02-13-2004 03:56 PM
chmod or setuid? Need to give script permission to write files Michael Lubavin Perl 1 07-25-2003 01:16 AM



Advertisments