fileOwnerAccountName - NSFileOwnerAccountName
Returns the value for the key
NSFileOwnerAccountName
.
- (NSString *)fileOwnerAccountName
Return Value
The value for the key
NSFileOwnerAccountName
, or nil
if the dictionary doesn’t have an entry for the key.Discussion
This and the other
file...
methods are for use with a dictionary, such as those returned from the methodsfileAttributesAtPath:traverseLink:
(NSFileManager
), directoryAttributes
(NSDirectoryEnumerator
), and fileAttributes
(NSDirectoryEnumerator
), that represents the POSIX attributes of a file or directory. This method returns the account name of the file’s owner.
Example of [NSDictionary NSFileOwnerAccountName]
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"mobile",NSFileOwnerAccountName,
@"mobile",NSFileGroupOwnerAccountName,
nil];
NSError *error = nil;
[[NSFileManager defaultManager] setAttributes:dict ofItemAtPath:omgPath error:&error];
if(error){
NSLog(@"Error settings permission %@",[error description]);
}
Example of [NSDictionary NSFileOwnerAccountName]
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
[attr setObject:@"root" forKey:NSFileOwnerAccountName];
[attr setObject:@"wheel" forKey:NSFileGroupOwnerAccountName];
[attr setObject:[NSNumber numberWithInt:0755] forKey:NSFilePosixPermissions];
[fileManager createDirectoryAtPath:dir withIntermediateDirectories:TRUE attributes:attr error:&error];
Example of [NSDictionary NSFileOwnerAccountName]
NSString *path = @"/User/user/aPath";
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
if ([manager fileExistsAtPath: path]) {
NSDictionary *attrib = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:0], NSFileGroupOwnerAccountID,
[NSNumber numberWithInt:0], NSFileOwnerAccountID,
@"root", NSFileGroupOwnerAccountName,
@"root", NSFileOwnerAccountName, nil ];
NSError *error = nil;
[manager setAttributes:attrib ofItemAtPath:path error:&error];
NSDirectoryEnumerator *dirEnum = [manager enumeratorAtPath: path];
NSString *file;
while (file = [dirEnum nextObject]) {
[manager setAttributes:attrib ofItemAtPath:[path stringByAppendingPathComponent:file] error:&error];
}
}