Fix local variables in Windows

Some versions of Windows take SETLOCAL _very_ seriously, so variables were not getting set correctly, and build failed. There was also an issue sometimes with paths in `mkdir` that is fixed here.

Issue #1930

@jlipps