0

我试图在 Objective C 中遍历一个目录。我可以在 Java 中执行此操作,但如何在 Objective C 中执行此操作却让我难以理解。我正在使用 XCode5 并试图远离 C++/C。

我有一些,但到目前为止,我错过了一些东西。

- (IBAction)buttonPush:(id)sender {
    NSLog(@"Button Pushed");
    NSOpenPanel*    panel = [NSOpenPanel openPanel];
    [panel setCanChooseDirectories:YES];
//    [panel setAllowsMultipleSelection:YES]; // not now
    [panel setMessage:@"Select one or more, files or directories."];

    [panel beginWithCompletionHandler:^(NSInteger result){
        NSLog(@"OPEN Pushed");
        if (result == NSFileHandlingPanelOKButton) {

            NSArray* urls = [panel URLs];
            [self parseArray:urls]; *// How do I use the URL?NSURL?
            // Need to know if selected is File or Directory.
            // If File, what is the file attributes
            // If Directory, list the contents of the directory: procedure to recursively handle*
}
4

1 回答 1

0

退房-[NSFileManager enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:]。Apple 的文档,包括一些示例代码,在这里

于 2013-10-19T20:37:06.037 回答