I want to get all filenames and directories from a provided web url so I can easily create links to those files/directories in my app.
I am having trouble figuring out the best way to parse the text file returned when using NSURLSession's 'dataTaskWithRequest' method since it returns all the data for the contents at the url (i.e. permissions, date created, owner, group, etc.).
Here is how I get the data from a Web URL:
let request = NSURLRequest(URL: url)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request) {[weak self] (data, response, error) -> Void in
print("Data: \(data)")
print("Response: \(response)")
print("Error: \(error)")
if let weakSelf = self, let data = data, let results = NSString(data: data, encoding: NSASCIIStringEncoding)
{
...how do I parse out the file/directory names???...
}
}
task.resume()
Here is an example of string returned from a given URL:
drwxrwxr-x 26 65534 65534 65536 Sep 20 03:29 Movies
drwxrwsr-x 3 0 65534 65536 Jul 09 2013 Network Trash Folder
drwxrwxr-x 41 65534 65534 65536 Aug 24 15:58 TV
drwxrwsr-x 3 0 65534 65536 Jul 09 2013 Temporary Items
I need to be able to easily and accurately parse out the file/directory names ONLY so I can create links to them. Suggestions?