いくつかのpdfファイルをダウンロードするためのディレクトリを作成しようとしています。私は他のクラスとその作業で同じテクニックを使用しています. しかし、2 つのサブディレクトリを作成しようとしている 1 つの特定のクラスでは、NSString がパスの最後のスラッシュをストライピングしています。
私はこの方法を使用します:
- (NSString*)checkDirectory:(NSString*)path {
NSError *error = nil;
BOOL isDir = YES;
NSString *string = [NSHomeDirectory() stringByAppendingPathComponent:[@"/Documents" stringByAppendingFormat:@"/%@/",path]];
if(![[NSFileManager defaultManager]fileExistsAtPath:string isDirectory:&isDir]){
if (![[NSFileManager defaultManager]createDirectoryAtPath:string withIntermediateDirectories:NO attributes:nil error:&error]) {
NSLog(@"Create directory error %@",error);
}
}
return string;
}
変数パスは次のようになります。
/Reports/year2012/38week/
しかし、現時点では、パス コンポーネントを NSHomeDirectory() に追加すると、文字列がスラッシュから取り除かれ、アプリがディレクトリを作成できないことがわかります。