3
這裏是我的方法應該簡單地從/ someDirectory移動目錄的內容/插件/ ID/UUID:如何將一個目錄移動到新位置上的iPhone
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到/插件/ someDirectory而不是從/ someDirectory到/插件/ someDirectory/UUID:但是如果我改變pathToAddonDest相同的代碼工作。
任何想法,爲什麼一個看似簡單的重命名不會這樣工作?
幾乎正確。您必須創建路徑,直到正在移動的實際文件名爲止。所以/ addons/someDirectory必須存在,但/ addons/someDirectory/UUID不能存在。感謝您的想法! – Ross 2011-01-24 12:02:03