Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created October 27, 2011 14:52
Show Gist options
  • Save atduskgreg/1319757 to your computer and use it in GitHub Desktop.
Save atduskgreg/1319757 to your computer and use it in GitHub Desktop.
open modal file dialog in cocoa
int i; // Loop counter.
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:YES];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
// Loop through all the files and process them.
for( i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
// Do something with the filename.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment