私は通常NSBundle
を使ってパスを取得します。ドキュメントディレクトリ内のファイルのすべてのパスを取得するには?
ただし、NSBundle
にはDocumentsフォルダがありません。
どのようにドキュメントディレクトリ内のファイルのすべてのパス(または名前)を取得しますか?それからファイルを取得するには
私は通常NSBundle
を使ってパスを取得します。ドキュメントディレクトリ内のファイルのすべてのパスを取得するには?
ただし、NSBundle
にはDocumentsフォルダがありません。
どのようにドキュメントディレクトリ内のファイルのすべてのパス(または名前)を取得しますか?それからファイルを取得するには
これは、あなたがここ
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:0]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
は、あなたがパス構造を与えなければならない...
NSString *fileName = @"default.png";
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"%@", fileName];
FOLDERPATHはあなたに与えられたファイル名の場所を返します。
が迅速である以下のコードを使用してfilePathsArray内の各オブジェクトのパスを取得することができます
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);
ドキュメントディレクトリの下のuすべてのファイルのパスを提供します。
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
print("Paths - \(paths)")
let documentsDirectory = paths[0]
return documentsDirectory
}
ファイルではなく、ドキュメントディレクトリを印刷します。 – ChangUZ
私はコードを修正しました。これをチェックしてください。 –
申し訳ありませんが、指定されたファイル名ではなく、ドキュメント内のすべてのファイルのパスまたは名前がわかります。 – ChangUZ