Use Path instead of String to store file paths.

Also fixes a race condition when opening files by checking
for the files existence by trying to open the file, instead of
checking beforehand, which can lead to a race.

Credit to @pythonesque for discovering the race condition.