这是我的方法,它应该简单地将目录的内容从 /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。
任何想法为什么看似简单的重命名不能以这种方式工作?