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

发布于 2024-10-14 03:09:21 字数 1317 浏览 1 评论 0原文

这是我的方法,它应该简单地将目录的内容从 /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);

移动失败,并显示操作无法完成。 (可可错误4。)。 则相同的代码可以工作

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

但是,如果我将 pathToAddonDest 更改为:所以我可以从 /someDirectory 写入 /addons/someDirectory 但不能从 /someDirectory 写入 /addons/someDirectory/UUID,

。有什么想法为什么看似简单的重命名不能以这种方式工作吗?

Here's my method which should simply move the contents of a directory from /someDirectory to /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:

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2024-10-21 03:09:22

您应该先创建目录,然后才能将其移动到那里。
/addons/someDirectory/UUID --- 在尝试移动内容之前创建此路径。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文