Question

How can I use the Sys.chmod function in R to toggle readability by "other", i.e. the equivalent of:

chmod o+r myfile
chmod o-r myfile

I specifically want to leave the other parts of the mode alone.

Was it helpful?

Solution

chmod o+r:

mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod|4)

chmod o-r:

mod <- file.info('tmp.txt')$mode
Sys.chmod('tmp.txt', mod&!as.octmode(4))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top