Question

I need to import data inside a folder. The data comes from a linux box controlling a scientific instrument and the vendor put the results of each measurement into a folder and inside the folder are two files, one named "parameters" and the other named "data". My users will copy the folders over to their Mac and import the data into my program. If my app is not sandboxed I have no problem getting the contents of the folder, and reading the parameters and data files into my app. When my app is sandboxed, the NSOpenPanel tells me there are no urls inside the folder.

NSArray *files = [panel URLs];

returns an array with zero objects when there should be two. How do I make these files visible to my sandboxed app?

Was it helpful?

Solution

To make things easier for your users, try using the Open Panel the following way. This limits them to choose one directory (instead of both the files):

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setAllowsMultipleSelection:NO];
// don't set anything with setAllowedFileTypes:

You will then receive zero or one URL back (depending if user pressed OK or cancel) which points to the directory. Then use this URL together with a NSDirectoryEnumerator or something similar provided by NSFileManager to get the files inside the directory.

Also make sure you run the panel in an appropriate (not deprecated) manner using one of the following methods:

– beginSheetModalForWindow:completionHandler:
– beginWithCompletionHandler:
– runModal
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top