Fixed overwriting of files when Folder::SKIP is set
Add tests for #4521 and reformat code.

Add a regression test for #4521 as the original author didn't have one.
Reformat a long line since I was nearby already.

Closes #4521
Merge branch 'folder_overwrite_fix'

Merge pull request #4521 into master.