Re: Reading file permissions
Re: Reading file permissions
- Subject: Re: Reading file permissions
- From: Ed Watkeys <email@hidden>
- Date: Wed, 26 Nov 2003 14:42:58 -0500
Here's a class method you can add to a class to print out an extended
"ls -l" style permission string:
+ (NSString *)stringFromPermissions:(int) p {
char s[12];
strmode(p, s);
return [NSString stringWithUTF8String: s];
}
You can call it like this:
NSLog(@"%@", [YourClass stringFromPermissions: 0755]);
It uses strmode(). I found this by looking at the source code for "ls".
On a related note, if you want the octal representation of a number, do
this:
NSLog(@"%@", [NSString stringWithFormat: @"%o", 0644]);
I found out how to use "%o" by typing "man 3 printf" at the command
line. You could also have gotten to equivalent documentation by looking
at the Apple's documentation for NSString's stringWithFormat: class
method.
Ed
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.