且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“没有这样的文件或目录"创建目录时出错

更新时间: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;
}