如何将 iPhone 上的目录移动到新位置
这是我的方法,它应该简单地将目录的内容从 /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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该先创建目录,然后才能将其移动到那里。
/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.