简体   繁体   中英

differentiates files and folder from document directory iniphone

I am getting list of available files and folder in document directory by

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager]directoryContentsAtPath:bundleRoot];

I want to sprat list of files and folders from "discontents",How can i get such sprat away for files and folders?

To seperate the files and folder use this code

+ (void) seperateFilesAndFolders
{
    NSString *basePath = [CacheManager pathForCacheFolder];

    NSArray *dirContents = [[NSFileManager defaultManager]directoryContentsAtPath:basePath];

    //This will contains directories
    NSMutableArray *directories = [[NSMutableArray alloc] init];

    //This will contains files
    NSMutableArray *files = [[NSMutableArray alloc] init];

    for (NSString *str in dirContents) 
    {
        NSString *strFilePath = [basePath stringByAppendingPathComponent:str];

        BOOL isDirectory;
        if([[NSFileManager defaultManager] fileExistsAtPath:strFilePath isDirectory:&isDirectory])
        {
            if (isDirectory) {
                [directories addObject:str];
            }
            else {
                [files addObject:str];
            }
        }
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM