Exclude certain in a ad-hoc search

For example, I am inside folder A which contains a subfolder B. I want to search file that contains “foo” inside folder A but excluding folder B. Is this possible? It will be something like this:

group:A -group:A/B name:foo

The only possibilities right now are to either exclude group B from searching or to use a smart group which searches in group A but not in the subgroups.