如何在iPhone中查找文档目录中的内容

roc*_*key 1 iphone nsfilemanager

我想知道目录中的文件或其他任何内容.如果有一个文件或多个文件我需要这些文件名.实际上我在文档目录中创建导出目录..如果导出为空,那么我将zip文件从主包复制到导出文件夹

但以下代码无效.虽然导出是空的,但它不会进入那个如果阻止..还有任何隐藏的文件..?并且在最后一个for循环中它没有做任何事情.

这该怎么做.

请帮帮我

    self.fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    self.documentsDir = [paths objectAtIndex:0];
    //creating folder 'export' to recieve the file from iTunes
    NSString *srcFilePath = [NSString stringWithFormat:@"%@/export", self.documentsDir];
    [fileManager createDirectoryAtPath:srcFilePath 
           withIntermediateDirectories:NO
                            attributes:nil
                                 error:nil];
    //copying the zip file into exprort from bundle if export is empty
    if(![fileManager fileExistsAtPath:srcFilePath]) {
        NSLog(@"File exists at path: %@", srcFilePath);
        NSString *resZipfile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"zip" 
                                                         inDirectory:@"pckg"];
        NSLog(@"zip file path ...%@", resZipfile);
        NSData *mainBundleFile = [NSData dataWithContentsOfFile:resZipfile];
        [[NSFileManager defaultManager] createFileAtPath:srcFilePath 
                                                contents:mainBundleFile 
                                              attributes:nil];      
    }
    NSString *eachPath;
    NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:srcFilePath];

    for(eachPath in dirEnum) NSLog(@"FILE: %@", eachPath);
Run Code Online (Sandbox Code Playgroud)

Can*_*der 8

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];

NSFileManager *manager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *fileEnumerator = [manager enumeratorAtPath:documentsPath];

for (NSString *filename in fileEnumerator) {
    // Do something with file
}

[manager release];
Run Code Online (Sandbox Code Playgroud)