Rocky
Rocky

Reputation: 41

Get the list of files from document directory contains same name but with different extensions.

I need to get the list of files belongs to same name . Below are the files saved in document directory .
start.pdf , start.png , start_1.drawingpad , start_1.imagepad and other files like second.pdf , second.png .....

here .pdf , .png , .DrawingPad , .imagepad belongs to one set .

I need to list out these set , start.pdf , png , start_1.drawingpad and imagepad from document directory.

Upvotes: 0

Views: 32

Answers (1)

Mahesh Babu
Mahesh Babu

Reputation: 3433

Try this,This will result the array of values which contains matched string.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *renameArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];

NSString *strprdicate = [NSString stringWithFormat:@"SELF CONTAINS '%@'",@"start"];
 NSPredicate *predicate = [NSPredicate predicateWithFormat:strprdicate];
renameArray =  [renameArray filteredArrayUsingPredicate:predicate];

NSLog(@"files array %@", renameArray);

Make sure you should pass input string in '' if input is a string for NSPredicate.

Upvotes: 1

Related Questions