开发者

Problem with copying main application

OK , the eXercice is about to get the path to the running application i have done this by :

NSFileManager *FManager = [ NSFileManager defaultManager ] ;
NSString *CurrentPath = [ FManager currentDirectoryPath ] ;
NSDictionary *infoPList = [[NSBundle mainBundle] infoDictionary];
NSString *appName =开发者_如何学编程 [infoPList objectForKey:@"CFBundleName"];
NSString *mainpath = [ CurrentPath stringByAppendingPathComponent:appName ] ;
NSString *mainFile = [ mainpath stringByAppendingString:@".app" ] ;

then I try to copy the main file to the home directory

NSString *homedir = NSHomeDirectory();
if ( [ Fmanager fileExistsAtPath:mainfile ] == YES ) 
    NSLog(@" File exist " ) ;
else {
    NSLog(@" not eXist " );
}

if ( [ Fmanager copyItemAtPath:mainfile toPath:homedir error:NULL ] == YES ) {
    NSLog(@" COPY SUCC " ) ;
}
else {
    NSLog(@" COPY FAIL") ;
} 

here the copy procedure fails and it also tells me that the main file does not even eXists ...ou Can anyone help me please Thank you .


By main file, do you mean the main executable? Look at NSBundle for paths to various components of the compiled application.

[[NSBundle mainBundle] bundlePath]; // path to your.app
[[NSBundle mainBundle] executablePath]; // path to your.app main executable


It's usually a bad idea to rely on the value of the current directory unless you just set it. Anyway, you're making it too hard; the path to the app would be [[NSBundle mainBundle] bundlePath].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜