下面是我的方法,它只需将目录的内容从/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]];
所以我可以从/somedirectory写入/addons/somedirectory,但不能从/somedirectory写入/addons/somedirectory/uuid。
你知道为什么一个看似简单的名字就不能这样用吗?
最佳答案
您应该先创建目录,然后才能将其移到那里。
/addons/somedirectory/uuid---在尝试移动内容之前创建此路径。
关于iphone - 如何在iPhone上将目录移动到新位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4781624/