I have a button in an app that when clicked should cause a dialog box to open. The user then chooses a folder, clicks OK, and then the app displays the number of PDF files in that folder.
I have the following code implemented below. How do I scan a folder for the amount of PDF files in it?
- (IBAction)selectPathButton:(NSButton *)sender {
// Loop counter.
int i;
// Create a File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Set array of file types
NSArray *fileTypesArray;
fileTypesArray = [NSArray arrayWithObjects:@"pdf", nil];
// Enable options in the dialog.
[openDlg setCanChooseFiles:YES];
[openDlg setAllowedFileTypes:fileTypesArray];
[openDlg setAllowsMultipleSelection:TRUE];
// Display the dialog box. If the OK pressed,
// process the files.
if ( [openDlg runModal] == NSOKButton ) {
// Gets list of all files selected
NSArray *files = [openDlg URLs];
// Loop through the files and process them.
for( i = 0; i < [files count]; i++ ) {
}
NSInteger payCount = [files count];
self.payStubCountLabel.stringValue = [NSString stringWithFormat:@"%ld", (long)payCount];
}
}