coalib: Use dirname instead of split

This is more efficient and straightforward.