Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List saved files in iOS documents directory in a UITableView?

I have set up the following code to save a file to the documents directory:

NSLog(@"Saving File...");  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reddexuk.com/logo.png"]]; AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"logo.png"]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];  [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {     NSLog(@"Successfully downloaded file to %@", path); } failure:^(AFHTTPRequestOperation *operation, NSError *error) {     NSLog(@"Error: %@", error); }];  [operation start]; 

However, I wish to add each file to a UITableView when it is successfully saved. When the file in the UITableView is tapped, I'd like a UIWebView to navigate to that file (all offline).

Also - how can I just get the filename and ending such as "logo.png" instead of http://www.reddexuk.com/logo.png?

How can I do this?

like image 314
pixelbitlabs Avatar asked Dec 04 '11 15:12

pixelbitlabs


People also ask

What is Document Directory in Swift?

In the iOS application we have to store files, images, audios, videos. We can do it by creating folder in Document directory. Document directory stores user data to the given path in the apps. You can read apps data from the path of document directory.


1 Answers

Here is the method I use to get the content of a directory.

-(NSArray *)listFileAtPath:(NSString *)path {     //-----> LIST ALL FILES <-----//     NSLog(@"LISTING ALL FILES FOUND");      int count;      NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];     for (count = 0; count < (int)[directoryContent count]; count++)     {         NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);     }     return directoryContent; } 
like image 113
syclonefx Avatar answered Sep 28 '22 03:09

syclonefx