このコードを使用して、ファイルの最終変更日を取得しようとしています。
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath: myFilePath error:&error];
if (attributes != nil) {
NSDate *date = (NSDate*)[attributes objectForKey: NSFileModificationDate];
NSLog(@"Date modiifed: %@", [date description]);
}
else {
NSLog(@"Not found");
}
これは、メインバンドル内のファイルには適切に機能しますが、ファイルがアプリのドキュメントフォルダーのサブディレクトリにある場合は、次のように機能しませんmyFilePath
。
/Users/User/Library/Application Support/iPhone Simulator/6.0/Applications/The App ID Number/Documents/mySubdirectory/My Saved File
「見つかりません」を返し続けます。
ファインダーで表示できるので、ファイルがそこにあることがわかります。また、ファイル名のスペースを削除してみましたが、効果がありませんでした。
エラーログにはそのようなファイルやディレクトリは表示されないため、ファイルをドキュメントディレクトリにコピーしようとしたときに問題が発生したようです。
奇妙なことに、ドキュメントのサブディレクトリを繰り返し処理するとcontentsOfDirectoryAtPath
、ファイルが存在することが示されます。
パスをハードコーディングしてプログラムで取得しようとしましたが、次のようになりました。
*myFolder = [documentsDirectory stringByAppendingPathComponent:@"myFolder"];
*myFilePath = [myFolder stringByAppendingPathComponent:theFileName];
誰かが私がどこで間違っているのか見ることができますか?