0

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 :) :)

Community
  • 1
  • 1
Krunal
  • 1,318
  • 1
  • 13
  • 31

3 Answers3

1

You can check that either current item is folder or not by....

- (BOOL)createDirectoryAtURL:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error
iTrained
  • 31
  • 3
0

Have a look here, that's how you read in all existing directories:

Get array of directories in documents directory

You can then easily show them in a table in your view.

Community
  • 1
  • 1
TheEye
  • 9,280
  • 2
  • 42
  • 58
0

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
jmstone617
  • 5,707
  • 2
  • 24
  • 26