如何将一个目录移动到iPhone上的新位置?

时间:2022-10-29 15:44:16

Here's my method which should simply move the contents of a directory from /someDirectory to /addons/id/UUID:

这是我的方法,它应该简单地将目录的内容从/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 move fails with The operation couldn’t be completed. (Cocoa error 4.). However the same code works if I change pathToAddonDest to:

操作失败,无法完成移动。(可可错误4)。但是,如果我将pathToAddonDest更改为:

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

So I can write from /someDirectory to /addons/someDirectory but not from /someDirectory to /addons/someDirectory/UUID.

所以我可以从/someDirectory写入/addons/someDirectory,但不能从/someDirectory写入/addons/someDirectory/UUID。

Any ideas why a seemingly simple rename wouldn't work in this way?

你知道为什么一个看似简单的重命名不能用这种方式实现吗?

1 个解决方案

#1


3  

You should create directory before before you could move it there. /addons/someDirectory/UUID --- create this path before you try moving the content.

在将目录移动到那里之前,应该先创建目录。/addons/someDirectory/UUID——在尝试移动内容之前创建此路径。

#1


3  

You should create directory before before you could move it there. /addons/someDirectory/UUID --- create this path before you try moving the content.

在将目录移动到那里之前,应该先创建目录。/addons/someDirectory/UUID——在尝试移动内容之前创建此路径。