我目前正在使用NSFileManager setAttributes更改目录的权限。我的问题是它似乎没有递归地这样做。有什么办法强迫它这样做?
最佳答案
我认为没有内置的方法可以做到这一点,但是要做类似的事情并不难:
NSString *path = @"/The/root/directory";
NSDictionary *attributes; // Assume that this is already setup
NSFileManager *fileManager = [NSFileManager defaultManager];
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
}
}
}
这未经测试,但应该为您提供一个起点。
关于objective-c - 如何使用NSFileManager setAttributes递归更改目录的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55614549/