Search code examples
iphonexcodedirectorynsfilemanager

Issue in showing already created folder


I have been successful in creating folder in "Documents" folder in iPhone simulator.

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder"];
NSLog(@"path is:%@",dataPath);

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
{
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
}

I can see folder is created in simulator... Now I require to show that folder in my app screen. Means user can see( by clicking on '+' or anything else) that folder is created.

I have also referred iPhone/iPad: Unable to copy folder from NSBundle to NSDocumentDirectory but not as I require.....

Is is possible to show folder, created?? If yes, then how?? Any help would be appreciated....

Thanx in advance :) :)


Solution

  • You can't show the folder in the nib. A folder is not an object you can pull out from the object library. If you want an actual folder, you could use a UIImageView with an image of a folder. Also, if you are creating directories inside of the Documents folder, I would suggest using NSFileManager's methods for creating directories:

    - (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error
    

    or

    - (BOOL)createDirectoryAtURL:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error