You can use NSFileNanager to list all files, and then call the function of your choice. Your code will be something like this:
// From Apple FAQ #import <sys/xattr.h> - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); return result == 0; } - (void) addSkipBackupAttributeToItemsInFolder:(NSString*)folder { NSFileManager *fm = [NSFileManager defaultManager]; NSArray *dirContents = [fm contentsOfDirectoryAtPath:folder error:nil]; for (int curFileIdx = 0; curFileIdx < [dirContents count]; ++curFileIdx) { NSString* curString = [folder stringByAppendingPathComponent:[dirContents objectAtIndex:curFileIdx]]; NSURL* curFileUrl = [NSURL fileURLWithPath:curString]; [self addSkipBackupAttributeToItemAtURL: curFileUrl]; } }
And you will use it like this:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; [self addSkipBackupAttributeToItemsInFolder:documentsDirectory];
source share