At first B sims more intuitive, your selection is stoping where you pointed at, but...
Let's imagine a scenario:
A user wants to select 2 files form XLSX and one from DOCX. Ho often it will happen that this files are neighbours?
When I selecting files on my computers I usually have them in alphabetical order and give them similar names to make it possible. You need to have an order in your folders and files names to keep it possible, so I think such situation will happen rarely.
Another scenario: Selecting all files from few different types. If users don't keep too many file types in one folder, then we can safely say that it is possible that the types are neighbours.
The question is how often this pattern of selecting will happen? Also user can easily select them by crtl.
If you headings won't select then collapsing makes a difference.
In second image none of ODT fils is selected. IF we can collapse fills we don't want selected, then it is more possible that shift between types will be used. You can then turn this files into neighbours.
You can hint user about this behavior by selecting the headings once all of the files are selected.
Sumarizing: Option B, because user is stoping where he pointed, and because collapsing change fills selecting.