Make root_dir logic more robust/cross-platform

Fixes #7723 for windows support and generally makes it more platform-agnostic using syspaths.