Fix file interactions on Windows

Some nasty hacky in here.  Might break things on Unix.