Listing directory contents?

Discussion in 'iOS Programming' started by lynkynpark86, Feb 19, 2011.

  1. lynkynpark86 macrumors 6502

    #1
    Hello,
    I am making an app to play video files added by the user (by ssh, etc. It will be a jailbreak app). I am going to have a TableView with the videos in directory "/var/mobile/Media/Vid". How can I make it so an NSArray is set to the list of files in that directory (/var/mobile/Media/Vid)?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. lynkynpark86, Feb 19, 2011
    Last edited: Feb 19, 2011

    lynkynpark86 thread starter macrumors 6502

    #3
    I've been working on it, and I can't quite get it to work. Here's my code:
    Code:
    NSArray *dirList = [[NSFileManager defaultManager] directoryContentsAtPath:@"/var/mobile/Media/Vidly"];
    
    Is there anything wrong with this? I get no errors, but the tableview is blank, despite there being files in that directory. Ideas?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I don't have a jailbroken phone or any interest in supporting them. On a non-jailbroken device (and quite possibly on the simulator) your code cannot read from that directory so in those cases I'd expect you'd get an empty array. You'll probably get a better response on forums more jailbrake development oriented: most posters here are not developing for jailbroken phones.

    Edit to add: you should also be supplying the error: parameter even if you pass nill to it. Without it the method name is not complete and won't work. Ultimately you'd be better supplying an error object so as you can check for errors that might tell you what is going wrong.

    What I am suggesting is:
    Code:
    NSError *error;
    NSArray *dirList = [[NSFileManager defaultManager] directoryContentsAtPath:@"/var/mobile/Media/Vidly" error:&error];
    if (error!=nil)
    {
    // Check the error
    }
    
    Note I typed that straight in here: you need to check for typos or silly logic errors!
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    Original post:
    Chek yor speling.
     
  6. lynkynpark86 thread starter macrumors 6502

    #6
    Nod taht eye dond appriciate teh replie, buut doz thayt rilly hellp mii owt mutch?
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    How could I tell? I don't have your device.

    You posted two inconsistent pathnames. I pointed out the inconsistency. It's up to you to confirm that one of them is, in fact, correct.
     

Share This Page