-1

I have saved many files in a folder in the documents directory. This is the path to one of them:

/var/mobile/Applications/120FD973-C902-405E-A645-B1651904CE9B/Documents/1127029/BusinessCard2258009241.card

I want to list the files in the folder (1127029), and I tried this:

    NSFileManager *fManager = [NSFileManager defaultManager];
    NSString *item;
    NSArray *contents = [fManager contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%d", FolderNumber]] error:nil];


    // >>> this section here adds all files with the chosen extension to an array
    for (item in contents){
        if ([[item pathExtension] isEqualToString:@"card"]) {

...

But it doesn't work

Alessandro
  • 4,000
  • 12
  • 63
  • 131
  • 1
    Have you debugged your code at all? Have you verified that your path is correct? Break up your code so you actually see the value for the path you are accessing. And do some searching on how to properly get access to the `Documents` folder. – rmaddy Nov 29 '13 at 23:26
  • bro am not pretty sure but it should some thing like [NSString stringWithFormat:@"Documents/%d", documentsDirectory]] error:nil]; – Saad Chaudhry Nov 29 '13 at 23:29
  • here you can have a reference [link](http://stackoverflow.com/questions/5619719/write-a-file-on-ios) – Saad Chaudhry Nov 29 '13 at 23:31
  • solved ??? got what you are looking for – Saad Chaudhry Nov 30 '13 at 00:07
  • Why have I been down-voted? It seems to me a reasonable question... – Alessandro Nov 30 '13 at 12:35

1 Answers1

1

Don't try to get to the documents directory that way. It won't work. Use this code fragment instead:

NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

Then use stringByAppendingPathComponent: to add the subdirectory name.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • If my answer resolved your problem then an up-vote would be appreciated. (I'm not the one who down-voted you) – Duncan C Nov 30 '13 at 15:04