Question: Assume I have a dataframe:

```
Col1   Col2   Col3   Val
  a      1      a     2
  a      1      a     3
  a      1      b     5
  b      1      a     10
  b      1      a     20
  b      1      a     25

```

I want to aggregate across all columns and then attach this to my dataframe so that I have this output:

```
Col1   Col2   Col3   Val    Tot
  a      1      a     2      10
  a      1      a     3      10
  a      1      b     5      10
  b      1      a     10     55
  b      1      a     20     55
  b      1      a     25     55

```

Is there something I can do with `tapply` to accomplish this? I'm a little stuck on the most efficient way.

Answer: 
No guarantees in terms of performance, but for each directory you could check its files to see if it contains any with the matching extension:

```
List<string> imageDirectories = Directory.GetDirectories(sourceTextBox.Text, "*", SearchOption.AllDirectories)
    .Where(d => Directory.EnumerateFiles(d)
        .Select(Path.GetExtension)
        .Where(ext => ext == ".png" || ext == ".jpg")
        .Any())
    .ToList();

```
There is no built in way of doing it, You can try something like this

```
var directories = Directory
.GetDirectories(path, "*", SearchOption.AllDirectories)
.Where(x=> Directory.EnumerateFiles(x, "*.jpg").Any() || Directory.EnumerateFiles(x, "*.png").Any())
.ToList();

```