Don't write files before creating the directory in the first place.
Merge pull request #4190 from thedax/win32Fix

Win32: Don't write files before creating the directory in the first place.