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;
}
- (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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With