第44月第27天 iOS遍历文件夹 获取文件后缀
1.
// 工程目录 NSString *BASE_PATH = @"Path"; NSFileManager *myFileManager = [NSFileManager defaultManager]; NSDirectoryEnumerator *myDirectoryEnumerator = [myFileManager enumeratorAtPath:BASE_PATH]; BOOL isDir = NO; BOOL isExist = NO; //列举目录内容,可以遍历子目录 for (NSString *path in myDirectoryEnumerator.allObjects) { NSLog(@"%@", path); // 所有路径 isExist = [myFileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", BASE_PATH, path] isDirectory:&isDir]; if (isDir) { NSLog(@"%@", path); // 目录路径 } else { NSLog(@"%@", path); // 文件路径 } } }
https://www.jianshu.com/p/8e77fcec13f2
2.
// 从路径中获得完整的文件名(带后缀) exestr = [filePath lastPathComponent]; NSLog(@"%@",exestr); // 获得文件名(不带后缀) exestr = [exestr stringByDeletingPathExtension]; NSLog(@"%@",exestr); // 获得文件的后缀名(不带'.') exestr = [filePath pathExtension]; NSLog(@"%@",exestr);
http://blog.sina.com.cn/s/blog_9cd1705d0101mvk0.html