2010-06-28 70 views
0

确定,eXercice即将获得到正在运行的应用程序我有这样做的路径:问题的复制主要应用

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" ] ; 

然后我尝试将主文件复制到主目录

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") ; 
} 

这里复制过程失败,它也告诉我,主文件甚至不eXists ... ou 任何人都可以帮我请 谢谢。

+0

下次格式化您的代码。 – 2010-06-28 16:18:42

回答

0

除非您只设置它,否则依赖当前目录的值通常是一个糟糕的主意。无论如何,你让它太难了。该应用程序的路径将是[[NSBundle mainBundle] bundlePath]

+0

Thnx,但我不明白这里是[[NSBundle mainbundle] executablepath]应该返回到主要可执行文件的路径,它不是这种情况,它返回给我: /用户/ mayname /库/应用程序支持/ iPhone Simulator/4.0/Applications/9FAA4D2E-D826-42D9-B068-D0B715064C59/Testme.app/Testme 有人可以向我解释这个,以及我应该使用Bundlepath或executablePath? 谢谢 – Archer 2010-06-29 10:30:28

+0

这是主要可执行文件的路径。 – 2010-06-29 13:05:03

1

通过主文件,你的意思是主要的可执行文件?查看NSBundle以获取已编译应用程序的各种组件的路径。

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