Priya
Priya

Reputation: 61

In search display controller, search only current files and folder not subfolder and files in iPad

I am working on a file Manager application, if user search for a keyword then all the files and folders which are available at given path,filename should listed in a table view which have that search keyword. The Search must be same as in finder for specific folder.

Issue is - When I search any keyword it's display only current folder or files which in table view but I want to display all subfolder's files also.

E.g
LocalFolder

         ->>      **folder1**
                     -->f1.txt
                     -->f2.png
                     -->folder11
         ->>      **folder2**  

In this case, when you search something it display current folder/files like folder1 and folder2. I need to find into subdirectory also.

Upvotes: 1

Views: 200

Answers (2)

Priya
Priya

Reputation: 61

Thanks... Yes, I am using contentsOfDirectoryAtPath and now, I checked with subpathsOfDirectoryAtPath in function of getfilesandfolder. It's amazing. Display path with subfolder and files. But issue is that when I search any word or character, then containing files and folder are not display(result not found).Using this subpathsOfDirectoryAtPath it would be display all files and folder with subpath name.

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{

    [marrFiles removeAllObjects];

    for (NSDictionary *tempDict in marrTmp)

  {
        NSString *tempStr = @"";

     if ([tempDict valueForKey:@"Folder"])
        {
            tempStr = [tempDict valueForKey:@"Folder"];
        }else{
            tempStr = [tempDict valueForKey:@"File"];
        }


       if ([tempStr rangeOfString:searchString].location != NSNotFound) {
            [marrFiles addObject:tempDict];
        }
    }

    return YES;
}

Upvotes: 0

ujell
ujell

Reputation: 2792

I'm not sure how you made the file search, but i assume you use contentsOfDirectoryAtPath while getting paths from the search directory. Use subpathsOfDirectoryAtPath instead contentsOfDirectoryAtPath, it retruns the paths of all of the contained subdirectories.

NSArray * contents = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath: searchPath error:nil]; 
// Now make your search.

Look documentation for more information.

Upvotes: 0

Related Questions