递归目录遍历

时间:2013-10-19 20:31:22

标签: cocoa

我正在尝试在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*
}

1 个答案:

答案 0 :(得分:0)

结帐-[NSFileManager enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:]。 Apple的文档,包括一些示例代码,是here