iOS 获取document目录下的所有文件名和文件路径,当需要获取本地的文件,进行上传或者发送的时候,可以使用以下方法或者到。
-(NSMutableDictionary *)localFile {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath:path];
NSString *fileName;
NSMutableDictionary *R = [NSMutableDictionary dictionary];
while (fileName = [dirEnum nextObject]) {
NSLog(@"短路径:%@", fileName);
NSLog(@"全路径:%@", [path stringByAppendingPathComponent:fileName]);
if ([fileName hasSuffix:@".png"]) {
NSString *key = [fileName componentsSeparatedByString:@"/"].lastObject;
[R setObject:fileName forKey:key];
}
}
return R;
}
网友评论