Firstly the syntax with $(variable##pattern} and ${variable%%pattern) are in the "man" pages for Posix shells.
In your original post you used ${file##*/} to remove the leading path portion from ${file}. Here we are taking the result from that elimination and removing it from the end of ${file} to leave the path.
echo "${file%%${file##*/}}"
It could equally be done in two stages and been easier to read.
There will no doubt be a better method.
Forgot to mention. In day-to-day scripting I actually prefer "dirname" and "basename" because any scripter understands that method.