更新时间:2022-06-23 05:29:16
获取文档目录的方法如下:
Here's the way to get the documents directory:
- (NSString *)documentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return (paths.count)? paths[0] : nil;
}
然后,构建文件的路径:
Then, to build the path to your file:
- (NSURL *)thumbnailDirectoryWithName:(NSString *)theName {
NSString *namePath = [[self documentsDirectory] stringByAppendingPathComponent:theName];
NSString *thumbnailsPath = [namePath stringByAppendingPathComponent:@"Thumbnails"];
NSURL *thumbnailsURL = [NSURL fileURLWithPath:thumbnailsPath];
NSError *error;
if ([[NSFileManager defaultManager] fileExistsAtPath:thumbnailsPath] == NO) {
[[NSFileManager defaultManager] createDirectoryAtURL:thumbnailsURL withIntermediateDirectories:YES attributes:nil error:&error];
if (error) {
NSLog(@"[Thumbnail Directory] %@", [error description]);
return nil;
}
}
return thumbnailsURL;
}