读取IOS的相应路径

时间:2022-09-24 03:51:35

//    IOS相应路径

NSString* bundlePath = [[NSBundle mainBundle] bundlePath];

NSLog(@"bundlePath = %@", bundlePath);

//    documents

NSString* documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject];

NSLog(@"documentsDirectory = %@", documentsDirectory);

//    Library

NSString* libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];

NSLog(@"libraryDirectory = %@", libraryDirectory);

//    Cache

NSString* cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

NSLog(@"cacheDirectory = %@", cacheDirectory);

//    读取路径下所有文件

NSFileManager* fm = [NSFileManager defaultManager];

NSArray* array = [fm contentsOfDirectoryAtPath:MusicPath error:nil];

NSLog(@"%@", array);

//所有文件和文件夹

NSDirectoryEnumerator* dirEnum = [fm enumeratorAtPath:MusicPath];

NSLog(@"dirEnum = %@", dirEnum);

for (NSString* fileName in dirEnum) {

NSLog(@"%@", fileName);

}