title: How to set NSURL Resource Values for all files and folders within a folder
body: <p>I'm trying to prevent a whole folder and its contents from backing up to iCloud, by setting its <code>NSURLIsExcludedFromBackupKey</code> to <code>1</code>, as indicated in the <a href="https://developer.apple.com/library/ios/#qa/qa1719/_index.html" rel="nofollow noreferrer">guidelines</a>. I'm able to set the key to the folder's URL, but all the data I then save inside it has <code>0</code> for its <code>NSURLIsExcludedFromBackupKey</code>...</p>
  
  <p>Here's my code:</p>
  
  <pre><code>//create the directory:
  [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];
  NSURL *folderURL = [NSURL fileURLWithPath:path isDirectory:YES];
  
  //prevent backup:
  NSError *preventBackupError = nil;
  BOOL success = [folderURL setResourceValue: [NSNumber numberWithBool: YES]
                                      forKey: NSURLIsExcludedFromBackupKey
                                       error: &amp;preventBackupError];        
  
  //this prints 1 and 1:
  NSLog(@"resource values for directory: %@", [folderURL resourceValuesForKeys:@[NSURLIsExcludedFromBackupKey, NSURLIsDirectoryKey] error:nil]);
  </code></pre>
  
  <p>Now, if I then save a file (in this case it's <code>config.xml</code>) inside a subdirectory of <code>folderURL</code> and then do:</p>
  
  <pre><code>NSURL *fileURL = [NSURL fileURLWithPath:[path stringByAppendingPathComponent:@"config.xml"]];
  if ([[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) {
      NSLog(@"resource values for config file: %@", [configURL resourceValuesForKeys:@[NSURLIsExcludedFromBackupKey] error:nil]);
  } 
  </code></pre>
  
  <p>This prints <code>NSURLIsExcludedFromBackupKey = 0;</code></p>
  
  <p>I checked other SO answers such as <a href="https://stackoverflow.com/questions/10836134/nsurlisexcludedfrombackupkey-can-not-be-set-correctly">this one</a>, <a href="https://stackoverflow.com/questions/10866590/prevent-icloud-backup-of-folder">this one</a>, or <a href="https://stackoverflow.com/questions/12928509/cfurlsetresourcepropertyforkey-failed-when-disable-data-backup-on-nsdocumentdire">this one</a>, I can't see any difference in my syntax... </p>
  
  <p>So my question is, do I have to manually set that key to every single file inside the folder? Or am I doing something wrong?</p>
  
  <p>Cheers</p>