如何在iPhone上将目录移动到新位置
下面是我的方法,该方法只需将目录的内容从/someDirectory移动到/addons/id/UUID:如何在iPhone上将目录移动到新位置,iphone,objective-c,nsfilemanager,Iphone,Objective C,Nsfilemanager,下面是我的方法,该方法只需将目录的内容从/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
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)。但是,如果我将PathToAddEndest更改为:
NSString *pathToAddonDest = [LWEFile createDocumentPathWithFilename:[NSString stringWithFormat:@"addons/%@", [character objectForKey:@"shortName"], uuidString]];
因此,我可以从/someDirectory写入/addons/someDirectory,但不能从/someDirectory写入/addons/someDirectory/UUID
你知道为什么一个看似简单的重命名不能以这种方式工作吗?你应该先创建目录,然后才能将它移动到那里。
/加载项/someDirectory/UUID---在尝试移动内容之前创建此路径。几乎正确。您必须创建路径,直到实际文件名被移动为止。因此/addons/someDirectory必须存在,但/addons/someDirectory/UUID必须不存在。谢谢你的主意!