How to list all folders and their subdirectories/files in iPhone SDK?

后端 未结 5 1394
野趣味
野趣味 2020-12-14 12:00

I want the user to select any file present in her/his iPhone so that it’s used as an e-mail attachment. For this purpose, I want to show the list of all files and folders pr

5条回答
  •  天命终不由人
    2020-12-14 12:43

    You can use NSDirectoryEnumerator via NSFileManager.enumeratorAtPath

    From the docs:

    NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:  @"Documents"];
    NSFileManager *localFileManager=[[NSFileManager alloc] init];
    NSDirectoryEnumerator *dirEnum =
        [localFileManager enumeratorAtPath:docsDir];
    
    NSString *file;
    while ((file = [dirEnum nextObject])) {
        if ([[file pathExtension] isEqualToString: @"doc"]) {
            // process the document
            [self scanDocument: [docsDir stringByAppendingPathComponent:file]];
        }
    }
    

提交回复
热议问题