这是我的方法,它应该只是将目录的内容从/ 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.)。但是,如果我将pathToAddonDest更改为:
,则相同的代码可以正常工作NSString *pathToAddonDest = [LWEFile createDocumentPathWithFilename:[NSString stringWithFormat:@"addons/%@", [character objectForKey:@"shortName"], uuidString]];
所以我可以从/ someDirectory写到/ addons / someDirectory但不能从/ someDirectory写到/ addons / someDirectory / UUID。
为什么看似简单的重命名不会以这种方式起作用?
答案 0 :(得分:3)
您应该先创建目录,然后再将其移动到那里。 / addons / someDirectory / UUID ---在尝试移动内容之前创建此路径。