This might sound mad, but I have expereince in UNIX and experience in Java, but never worked with them togehter, so to be honest, I didn't realise they were not being displayed as octal in the first place.
You can get the permissions of a file using the getPermissions command.
Then it's just a matter of converting the string values to octal, by reading the first three digits in a string, and converting it, then the next three, and then the final three.
For example:
if (st = "---") {val = 0;}
if (st = "--x") {val = 1;}
if (st = "-w-") {val = 2;}
if (st = "-wx") {val = 3;}
if (st = "r--") {val = 4;}
if (st = "r-x") {val = 5;}
if (st = "rw-") {val = 6;}
if (st = "rwx") {val = 7;}
This isn't the full code, but I hope it gives you an idea of what you need to do.
|