How do I remove the file extension from a list of files in an NSArray in iOS 5
ios
Solution
- (IBAction)getFile:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory =[paths objectAtIndex:0];
NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSString *names = nil;
for (NSString *name in fileList){
if (!names) names = [[name lastPathComponent] stringByDeletingPathExtension];
else names = [names stringByAppendingFormat:@" %@",[[name lastPathComponent] stringByDeletingPathExtension]];
}
NSLog(@"File Name Is \n%@",names
}
Problem
Working in iOS 5 I have read a list of file names from my documents directory the array is called "file list". I am trying to get a list of file names without extensions. Only the last name in my list has the extension removed. Any ideas? ``` - (IBAction)getFile:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory =[paths objectAtIndex:0]; NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil]; NSString *names = [[[fileList valueForKey:@"description"]componentsJoinedByString:@"\n"]stringByDeletingPathExtension]; NSLog(@"File Name Is \n%@",names); showFile.text = names; } ```