2

NSFileManager を使用して、copyItemAtPath を使用して 1 つのファイル (ディレクトリ) をある場所から別の場所にコピーすると、エラーが発生します。

コードは次のとおりです。

 [[NSFileManager defaultManager]copyItemAtPath:@"/Users/name/Documents/localhost/websiteDesign/_Software/" toPath:@"/Volumes/NAME/" error:&handleError];
 NSLog(@"%@", [handleError description]);

エラーは次のとおりです。

 Error Domain=NSCocoaErrorDomain Code=516 "“_Software” couldn’t be copied to “Volumes”   because an item with the same name already exists." UserInfo=0x102842d00
 {NSSourceFilePathErrorKey=/Users/name/Documents/localhost/websiteDesign/_Software/, NSUserStringVariant=(Copy), NSDestinationFilePath=/Volumes/NAME/, NSFilePath=/Users/name/Documents/localhost/websiteDesign/_Software/, NSUnderlyingError=0x10283f8e0 "The operation couldn’t be completed. File exists"}

ただし、@"/Volumes/NAME/" である宛先ファイルの名前を @"/Volumes/aaa/" のような名前に変更すると、エラーはなくなります。何故かはわからない。ありがとう !!

4

1 に答える 1

4

実際のファイル名を含む完全なパス名を指定する必要があります。

copyItemAtPath:toPath:error:「toPath:」パラメーターの状態に関する Apple のドキュメント:

srcPath のコピーを配置するパス。このパスには、新しい場所にあるファイルまたはディレクトリの名前が含まれている必要があります。このパラメーターは nil であってはなりません。

あなたが今行っていることは、ハード ドライブ (ボリューム) 全体をファイルで上書きしようとしていることです。

于 2013-07-14T05:20:27.887 に答える