I have set up the following code to save a file to the documents directory:
NSLog(@\"Saving File...\");
NSURLRequest *request = [NSURLRequest requestWithURL
For a more reasonable filename:
NSString *filename = [[url lastPathComponent] stringByAppendingPathExtension:[url pathExtension]];
-(NSArray *)findFiles:(NSString *)extension{
NSMutableArray *matches = [[NSMutableArray alloc]init];
NSFileManager *fManager = [NSFileManager defaultManager];
NSString *item;
NSArray *contents = [fManager contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil];
// >>> this section here adds all files with the chosen extension to an array
for (item in contents){
if ([[item pathExtension] isEqualToString:extension]) {
[matches addObject:item];
}
}
return matches; }
The example above is pretty self-explanatory. I hope it answers you second question.
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;
}