Thursday, May 9, 2013

NSDictionary NSFileOwnerAccountID example ios


fileOwnerAccountID - NSFileOwnerAccountID

Returns the value for the NSFileOwnerAccountID key.
- (NSNumber *)fileOwnerAccountID
Return Value
The value for the NSFileOwnerAccountID key, or nil if the dictionary doesn’t have an entry for the key.
Discussion of [NSDictionary NSFileOwnerAccountID]
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 NSFileOwnerAccountID]
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];
  }
}
Example of [NSDictionary NSFileOwnerAccountID]
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = nil;
NSDictionary *attr = [fm attributesOfItemAtPath:@"/" error:&error];
if (!error) {
    NSLog(@"Attr: %@", attr);
}

2009-10-28 17:21:11.936 MyApp[33149:a0b] Attr: {
    NSFileCreationDate = "2009-08-28 15:37:03 -0400";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = 80;
    NSFileGroupOwnerAccountName = admin;
    NSFileModificationDate = "2009-10-28 15:22:15 -0400";
    NSFileOwnerAccountID = 0;
    NSFileOwnerAccountName = root;
    NSFilePosixPermissions = 1021;
    NSFileReferenceCount = 40;
    NSFileSize = 1428;
    NSFileSystemFileNumber = 2;
    NSFileSystemNumber = 234881026;
    NSFileType = NSFileTypeDirectory;
}