fileExistsAtPath
は存在するディレクトリに対してNOを返します。私は次のコードをお持ちの場合:ディレクトリはちょうどmoveItemAtURL
で正常に作成されているにもかかわらずfileExistsAtPathは存在するディレクトリに対してNOを返します。
NSURL *newDirectoryPath = ... // path does not begin with a tilda
// and is created using URLByAppendingPathComponent:isDirectory:
BOOL directoryExists = [self.fileManager fileExistsAtPath:[newDirectoryPath absoluteString]];
if (NO == directoryExists)
{
BOOL ret = [self.fileManager moveItemAtURL:self.currentPresentationDirectoryPath toURL:newDirectoryPath error: &err];
// ret is YES, err is nil
directoryExists = [self.fileManager fileExistsAtPath:[newDirectoryPath absoluteString]];
}
を、fileExistsAtPath
はまだNOを返しています。
私は、ドキュメントが、これは言う知っている: ファイルシステムやファイルシステム上の特定のファイルの現在の状態に基づいて行動を述語しようと
が 推奨されません。そうすることで、ファイル システム競合状態の場合に、奇妙な動作が発生する可能性があります。
しかし、私は問題がここにあるかを理解したい - 私はアプリを閉じてから、上記のコードでfileExistsAtPath
ための最初のチェックはまだNO戻っていることを再起動した場合、ディレクトリが以前に成功時に作成されたにもかかわらず、コードの実行前に、オーガナイザのディレクトリを見ることができ、ディレクトリの内容などからも正常に読むことができます。
PS方法はありますか?fileExistsAtURL
?
NSLogあなたが使用しているパスを確認し、それがあなたの考えであることを確認してください。 –
このマシンでテストすることはできませんが、[newDirectoryPath absoluteString]ではなく[newDirectoryPath path]であるはずです。 –
@ Joachim Isaksson - それはそれだった – Gruntcakes