Your code already processes the files that the user selected, you just do nothing with them.
The array returned from the ‑filenames method contains the paths to the files that the user ‑filenames as NSString objects. If they selected only one file, there will be only one object in the array. If they did not select files, the array will be empty.
if ([openDlg runModalForDirectory:nil file:nil] == NSOKButton ) { NSArray* files = [openDlg filenames]; for(NSString* filePath in [openDlg filenames]) { NSLog(@"%@",filePath);
If you want the user to be able to select a single file, call [openPanel setAllowsMultipleSelection:NO] when you configure the panel. Thus, there will be a maximum of one entry in the filenames array.
As @VenoMKO points out, the ‑filenames method ‑filenames now deprecated, and you should use the ‑URLs method ‑URLs . This will return an array of NSURL files, not an NSString s array. Since almost all of the file processing APIs in Snow Leopard have been revised to use URLs, this would be the preferred option.
source share