Fix file path handling on Windows.

This will fix Issue #513

I'll try to write some unit test.
But due to the test must run on both Unix and Windows with Windows file separator, I need some time to write it.
Thus it would be nice, if anyone check that this code seems ok or not before I write unit test.