Scanning in file names in a Directory

Discussion in 'iOS Programming' started by larswik, Feb 1, 2012.

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    Should I use the scanf or fgets to read in the file names of my PDF docs I have sitting in a directory in the phone? I want to display the name of the items in a tableview. I was unsure how to read in the file names that I would add to an NSArray.

    Thanks.
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  3. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    Look through the NSFileManager docs. You can read in the names of all the files in a folder in one method call.
     
  4. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #4
    Sorry, it was a dumb question. I was at the airport waiting on a 4 hour layover to Sweden. I had internet on my phone but not on my computer. I had no idea that the doc's needed the internet to work!

    Suddenly I had to rely on my memory and not the internet and doc's to help me with the answer. it is so slow using my iphone with data roaming to search anything. After 30 minutes I was able to reason it out. When I did I knem my scanf and fgets was the wrong thing to ask for.

    This code worked fine. Although I thought it was strange that I could not use the contentsOfDirectoryAtPath: with a mutableArray, it kept giving me a error so I used this code and then copied it to a mutableArray

    Code:
    -(void)readInDirectoryItems{
        NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/PDF"];
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSArray *tempArray = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:nil];
        itemsInDirectoryArray = [NSMutableArray arrayWithArray:tempArray];
        
        [self.tableView reloadData];
    }
    By the way, can I download the docs to my computer or does it allways need to relly on an internet connection?
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    You can download them. What does your Documentation preferences (under Downloads) in Xcode show?
     
  6. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
  7. macrumors 6502

    Joined:
    Jun 19, 2009
    #7
    Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

    If you do want viewable documentation on your iPhone or iPad, I've found that Apple has made several of them available as iBooks. It seems the rest are available as PDF files which iBooks does quite well at displaying. It's not a replacement for a computer, mind you, but it works great in a pinch.
     

Share This Page