3

ディレクトリの内容を /someDirectory から /addons/id/UUID に単純に移動する方法は次のとおりです。

  CFUUIDRef uuidObj = CFUUIDCreate(nil); //create a new UUID
  //get the string representation of the UUID
  NSString *uuidString = (NSString*)CFUUIDCreateString(nil, uuidObj);

  //MOVE the addon to the addons directory addons/shortname/UUID
  NSString *pathToAddon = [LWEFile createDocumentPathWithFilename:[NSString stringWithFormat:@"%@", relPath]];
  NSString *pathToAddonDest = [LWEFile createDocumentPathWithFilename:[NSString stringWithFormat:@"addons/%@/%@", [character objectForKey:@"shortName"], uuidString]];

  // move the files
  NSError* error;
  if([[NSFileManager defaultManager] moveItemAtPath:pathToAddon toPath:pathToAddonDest error:&error] != YES)
  {
    NSLog(@"Unable to move file: %@", [error localizedDescription]);
  }

  //release the uuid stuff
  [uuidString release];
  CFRelease(uuidObj);

The operation could not be completed で移動が失敗します。(ココア エラー 4)。ただし、pathToAddonDest を次のように変更すると、同じコードが機能します。

NSString *pathToAddonDest = [LWEFile createDocumentPathWithFilename:[NSString stringWithFormat:@"addons/%@", [character objectForKey:@"shortName"], uuidString]];

したがって、/someDirectory から /addons/someDirectory に書き込むことはできますが、/someDirectory から /addons/someDirectory/UUID に書き込むことはできません。

一見単純な名前変更がこのように機能しない理由はありますか?

4

1 に答える 1

3

そこに移動する前に、ディレクトリを作成する必要があります。/addons/someDirectory/UUID --- コンテンツを移動する前に、このパスを作成してください。

于 2011-01-24T11:56:35.180 に答える