chmod -R u+X in ruby

Discussion in 'Ruby' started by Tammo Tjarks, Jul 26, 2008.

  1. Tammo Tjarks

    Tammo Tjarks Guest

    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 Tjarks, Jul 26, 2008
    #1
    1. Advertising

  2. Tammo Tjarks

    Phlip Guest

    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)
     
    Phlip, Jul 26, 2008
    #2
    1. Advertising

  3. Tammo Tjarks

    Tammo Tjarks Guest

    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
     
    Tammo Tjarks, Jul 26, 2008
    #3
  4. 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/.
     
    Joshua Ballanco, Jul 28, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Lubavin
    Replies:
    1
    Views:
    3,082
    Steve Grazzini
    Jul 25, 2003
  2. Brad Cooper

    Chmod from Runtime.Exec

    Brad Cooper, May 13, 2004, in forum: Java
    Replies:
    3
    Views:
    10,112
    Brad Cooper
    May 13, 2004
  3. Bob K.
    Replies:
    9
    Views:
    1,591
    PeterMcC
    Jul 5, 2004
  4. Fuzzyman

    Understanding CHMOD

    Fuzzyman, Feb 13, 2004, in forum: Python
    Replies:
    6
    Views:
    795
    Fuzzyman
    Feb 13, 2004
  5. James Colannino

    Re: weird problem with os.chmod

    James Colannino, Nov 12, 2005, in forum: Python
    Replies:
    6
    Views:
    391
    Fredrik Lundh
    Nov 12, 2005
Loading...

Share This Page