2010-03-29 3 views

Antwort

4

Ich glaube nicht, gibt es eine integrierte Methode, dies zu tun, aber es sollte so etwas wie nicht schwer zu tun:

NSString *path = @"/The/root/directory"; 
NSDictionary *attributes; // Assume that this is already setup 


NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease]; 
NSArray *subPaths = [fileManager subpathsAtPath:path]; 
for (NSString *aPath in subPaths) { 
    BOOL isDirectory; 
    [fileManager fileExistsAtPath:aPath isDirectory:&isDirectory]; 
    if (isDirectory) { 
     // Change the permissions on the directory here 
     NSError *error = nil; 
     [fileManager setAttributes:attributes ofItemAtPath:aPath error:error]; 
     if (error) { 
      // Handle the error 
     } 
    } 
} 

Dies ist nicht getestet, aber sollten Sie einen Ausgangspunkt geben.

2
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]; 
    } 
} 
Verwandte Themen