2010-08-12 66 views
0

我可以訪問.txt文件從文件夾,但如何訪問一個文件夾中的內容文件讓說文件/ A如何訪問一個文件夾中使用iphone

A內,我有 - > a.html, update.cfg

現在爲什麼我不能訪問update.cfg ??

我是越來越空值zipPath

我想這,但沒有運氣

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *aDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"A"]; 

     NSString *zipPath = [[NSBundle mainBundle] pathForResource:@"update" ofType:@"cfg" inDirectory:aDirectory]; 

仍然zipPath = NULL?

+0

查找的NSFileManager在蘋果文檔 – Akusete 2010-08-12 04:20:34

+0

你說的是這個[fileManager copyItemAtPath:bundlePath toPath:destinationPath error:&error]; ??? 我真的不知道如何去文件夾damm :( – ram 2010-08-12 04:35:02

回答

0

搞亂了後,我發現這種方式從文件夾存取權限的文件

我得到它

 NSString *fileName = [NSString stringWithFormat:@"%@/update.cfg", 
            aDirectory]; 
NSString *content = [[NSString alloc] initWithContentsOfFile:fileName 
                 usedEncoding:nil 
                   error:nil]; 

感謝

0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *aDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"A"]; 
+0

感謝plz查看更新 – ram 2010-08-12 04:43:35

0

我的方法來到文檔文件夾是有點不同。 (我希望你的意思,其每個應用程序都有,沒有一個自己在mainbundle創建的文檔文件夾^^)。我不喜歡這樣寫道:

NSString *directoryPath = [[NSHomeDirectory() stringByAppendingPathComponent: @"Documents"] stringByAppendingPathComponent: @"A"]; 

這是通向你的目錄稱爲A的文件夾。如果您知道文件名,則可以使用另一個「stringByAppendingPathComponent」。 ;-)我希望它有幫助。否則再問一次。 :-D

+0

感謝您的代碼,但它的空再次這是我的路徑 用戶/蘋果/圖書館/應用程序支持/ iPhone模擬器/ 3.1.3 /應用程序/ CF6EAADC-FC80-4718-8096-35CA3D97AD86/Documents/A 我想訪問update.cfg裏面:( – ram 2010-08-12 07:10:15

+0

我需要使用[[NSBundle mainBundle]路徑嗎??? – ram 2010-08-12 07:13:31

+0

不是。我的解決方案應該在這種情況下工作,因爲NSHomeDirectory()給你的文件夾的路徑與長奇怪的名字。比2倍stringByAppendingPathComponent,你在你的A文件夾。再次與文件名,你有你的整個路徑文件... – 2010-08-12 07:58:42

相關問題