4
FM = [NSFileManager defaultManager];
directoryContents = [FM contentsOfDirectoryAtPath:@"/Users/myComputer/Library/Application Support/iPhone Simulator/4.3/Applications/CD88649C-E545-4E10-84DF-F4E5D829641B/Documents" error:NULL];

but it gives me object not the path for object.

iSagar
  • 107
  • 1
  • 11

3 Answers3

3

I found out how to read files stored in directory. By using:

[[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil]

It returns the file or folder name stored at that location. Then we can again append these names in a string to read these files.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
iSagar
  • 107
  • 1
  • 11
2
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
for (NSString *tString in dirContents) 
{
  //Do some stuff here  
}

See this Post Get directory contents in date modified order

Community
  • 1
  • 1
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
0

I really not understand the hardcoded string for the bundle path use below for getting the bundle path

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];

your code must be similar with below.

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76