检索Documents目录的完整路径的两种方法:
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
判断Documents下的某个资源文件是否存在
NSString *filename=@"123.mp3";
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filename];
if(![fileManager fileExistsAtPath:filePath])
{
NSLog(@"文件不存在");
}else{
NSLog(@"文件存在");
}
网友评论