Paul Lutus wrote: > App Ra wrote: > >> I'm trying to change permission on a file on a windows machine. This >> should work according to the documentation (may be i'm missing something >> here). But it doesn't > > Be specific. What did you expect, and what did you get instead? Any error > messages? > >> here is the code: >> >> # take away read permission >> new_permission = File.lstat("testfile").mode ^ 0004 > > Hoo-boy. Do you know what "^" actually does? Do it this way: > > x & 4 ^ 0xffff > > Meaning original value "AND" the bit-flip of the desired pattern. That > way, you actually get a predictable result, regardless of the original > value, instead of an unpredictable toggle. Let me add, for clarity, to SET bit 2 (starting at 0 = LSB): x |= 4 to CLEAR bit 2: x &= 4 ^ 0xffff The idea is to act only on the chosen bit and have no effect on any other bits. -- Paul Lutus http://www.arachnoid.com