[WIP] Move more functions into path.c

Moving more path/file-related stuff into path.c to make refactoring easier.