Fix cross-platform bugs [thanks to Arrvi]

Fix cross-platform file manipulation bugs