我通过
获取文档目录中的可用文件和文件夹列表NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager]directoryContentsAtPath:bundleRoot];
我想从“不满”中查看文件和文件夹的列表,我怎样才能获得文件和文件夹的文件和文件?
答案 0 :(得分:2)
要分隔文件和文件夹,请使用此代码
+ (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];
}
}
}
}