views:

198

answers:

2

How do I get an NSArray of the NAMES of all files stored in a specific directory such as: "http://www.someurl/somedirectory/"?

+1  A: 

That's really something that has to be generated server-side, then parsed on the device. I know Apache has an option where you can turn on Directory Indexes, so you could do that, then download the generated directory index and parse the HTML (using an NSXMLParser or some other parsing library), adding an NSString to an NSMutableArray every time you find a file name.

Tim
I see...What if i had a text file (in said directory) with all the file names, how could I get the contents of the text file from within my app? Then I could seperate the string using string functions and make an array of it.
RexOnRoids
I think you recently asked a question (http://stackoverflow.com/questions/1332127/how-to-download-files-from-internet-and-save-in-documents-on-iphone) about downloading an image from a web server. The process is the same for a text file, just convert the NSData object to an NSString afterwards.
Tim
+1  A: 

Should be something along these lines..

NSURL* url = [NSURL URLWithString: @"http://address.tld/path/files.txt"];
NSString* data = [NSString stringWithContentsOfURL: url];

if(data)
{
    NSArray* files = [data componentsSeparatedByString: @"\n"];

    for(NSString* filename in files)
    {
        NSLog(@"%@", filename);
    }
}
ttvd
Great example. Thanks ttvd
RexOnRoids