tags:

views:

53

answers:

3

i can access .txt file from documents folder but how to access a folder content lets say documents/A

inside A i have ->a.html, update.cfg

now why i cant access update.cfg??

i am getting null value for zipPath

i tried this but no luck

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

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

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

still zipPath=NULL??

A: 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *aDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"A"];
kovpas
thanks plz see updates
ram
A: 

My approach to get to the documentsfolder is a little bit different. (I hope you mean the Documents folder which every application has, not one created by yourself in the mainbundle.^^) I do it like this:

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

This is the path to your directory called A in the documents folder. If you know the filename, than you can use another "stringByAppendingPathComponent". ;-) I hope it helps. Else ask again. :-D

Sandro Meier
Thanks for that code but again its null this is my pathUsers/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/CF6EAADC-FC80-4718-8096-35CA3D97AD86/Documents/A and i want to access update.cfg inside A :(
ram
do i need to play with [[NSBundle mainBundle] path ???
ram
No. My solution should work in this case. Because NSHomeDirectory() gives you the path to the Folder with the long strange name. Than 2 times stringByAppendingPathComponent and you are in your A Folder. Than once again with the the file name and you have the whole path to your File...
Sandro Meier
The code I posted only brings you to the "A" Folder. You have to add another [pathToA stringByAppendingPathComponent:@"update.cfg"]. And then open the returned path with [NSString stringWithContentsOfFile:pathToFile]. Did you do that?
Sandro Meier
A: 

after messing up i found this way to acces the file from folder

i got it

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

thanks

ram