没有这样的文件或目录 iOS
No such file or directory iOS
我正在尝试通过文件的路径获取文件的大小。这些文件是从我的应用程序中保存的视频。我使用下面的代码返回错误,说没有文件或目录。
NSString *urlPath = [self.localPathArray objectAtIndex:indexPath.row];
NSError *err;
NSDictionary * properties = [[NSFileManager defaultManager] attributesOfItemAtPath:urlPath error:&err];
这是下载文件后保存文件路径的方式
- (void)URLSession:(NSURLSession *)session assetDownloadTask:
(AVAssetDownloadTask *)assetDownloadTask didFinishDownloadingToURL:(NSURL *)location {
NSString *localPath = location.relativePath;
NSLog(@"localPath: %@", localPath);
[[NSUserDefaults standardUserDefaults]setValue:self.localPathArray forKey:@"AssetPath"];
}
请参阅下面的错误屏幕截图和我的应用程序存储详细信息屏幕截图
The path with reference to root directory is called absolute. The path with reference to current directory is called relative
所以尝试
NSString *localPath = location.path;
而不是
NSString *localPath = location.relativePath;
例如
- (void)URLSession:(NSURLSession *)session assetDownloadTask:
(AVAssetDownloadTask *)assetDownloadTask didFinishDownloadingToURL:(NSURL *)location {
NSString *localPath = location.path;
NSLog(@"localPath: %@", localPath);
[self.localPathArray addObject: localPath];
[[NSUserDefaults standardUserDefaults]setValue:self.localPathArray forKey:@"AssetPath"];
}
示例见此答案已在 Stack overflow
中回答
我正在尝试通过文件的路径获取文件的大小。这些文件是从我的应用程序中保存的视频。我使用下面的代码返回错误,说没有文件或目录。
NSString *urlPath = [self.localPathArray objectAtIndex:indexPath.row];
NSError *err;
NSDictionary * properties = [[NSFileManager defaultManager] attributesOfItemAtPath:urlPath error:&err];
这是下载文件后保存文件路径的方式
- (void)URLSession:(NSURLSession *)session assetDownloadTask:
(AVAssetDownloadTask *)assetDownloadTask didFinishDownloadingToURL:(NSURL *)location {
NSString *localPath = location.relativePath;
NSLog(@"localPath: %@", localPath);
[[NSUserDefaults standardUserDefaults]setValue:self.localPathArray forKey:@"AssetPath"];
}
请参阅下面的错误屏幕截图和我的应用程序存储详细信息屏幕截图
The path with reference to root directory is called absolute. The path with reference to current directory is called relative
所以尝试
NSString *localPath = location.path;
而不是
NSString *localPath = location.relativePath;
例如
- (void)URLSession:(NSURLSession *)session assetDownloadTask:
(AVAssetDownloadTask *)assetDownloadTask didFinishDownloadingToURL:(NSURL *)location {
NSString *localPath = location.path;
NSLog(@"localPath: %@", localPath);
[self.localPathArray addObject: localPath];
[[NSUserDefaults standardUserDefaults]setValue:self.localPathArray forKey:@"AssetPath"];
}
示例见此答案已在 Stack overflow
中回答