Hi Cocoa-dev People,

I have a sandboxing question, below. I'm wondering if it's even possible to do 
what I tried to do, and if so, how?

Joel Norvell

I'm trying to iterate directories in a sandboxed app in order to find a file 
with a specific extension.

I believe I have all the entitlements that are available that might help:

App Sandbox

I need to be able to find a file, by name, that could either be on the Desktop 
or in the (real) Documents folder. I don't even get close. I get a 
filecoordinationd when I try to iterate either of them (code below). I am able 
to find a file, by name, in the Downloads folder, though.

Has anyone been able to do this with the Desktop folder or the (real) Documents 
folder? (When I used NSDocumentDirectory it looked in the Documents folder 
attached to my container. I could find things that were in that. But it wasn't 
the same as the Documents folder that the user sees.)

If I turn off Sandboxing I have no problem iterating Desktop or Documents.

This is the code I used to test iterating in three NSSearchPathDirectories: 
NSDocumentDirectory, NSDesktopDirectory, and NSDownloadsDirectory.

NSFileManager* fm = [NSFileManager new];
NSError* err = nil;
NSURL* rootDirURL =
[fm URLForDirectory:NSDesktopDirectory
        inDomain:NSUserDomainMask appropriateForURL:nil
        create:NO error:&err];
        // error-checking omitted
NSURL * theFormsFolderURL = [self formsFolderURL:rootDirURL];

- (NSURL *) formsFolderURL:(NSURL *)rootDirURL
  NSFileManager * fm = [NSFileManager defaultManager];
  NSDirectoryEnumerator* dir = [fm enumeratorAtURL:rootDirURL 
                               options:0 errorHandler:nil];

  for (NSURL* f in dir)
    if ([[f pathExtension] isEqualToString:@"pdq"])
      NSLog(@"%@", [f lastPathComponent]);

  return nil;     // Dummy nil

BTW, this was the value that gave me a filecoordinationd for Desktop:
rootDirURL NSURL * 

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to arch...@mail-archive.com

Reply via email to