From: yermej Date: 2007-11-26T07:40:02+09:00 Subject: Re: Has anyone used File.stat to check permissions On Nov 25, 3:29 pm, Peter Loftus wrote: > In ruby API there is an example > > s = File.stat("testfile") > sprintf("%o", s.mode) #=> "100644" > > I need to check the last three numbers from the octal notation which is > "644" > which means: > rw- for user > r-- for group > r-- for other > > Does anyone know how i could check just those three numbers and leave > the rest > > Regards > Loftz > -- > Posted viahttp://www.ruby-forum.com/. If you're wanting to compare to the String "644": s.mode.to_s(8)[-3..-1] == "644" otherwise, you can mask using bitwise & and compare to the Fixnum 0644: (s.mode & 0xFFF) == 0644 (s.mode & 07777) == 0644 Jeremy